How to make an execution test case

From EdnaWiki
Jump to: navigation, search

The execution test cases inherit from EDTestCasePluginExecute and should implement a process method that adds in the various test methods. The test methods should actually run the plugin. Here's a simple example of a process method:

 def process( self ):
       """
       Adds the plugin execute test methods
       """
       self.addTestMethod( self.testExecute )

The testExecute method then runs the plugin and compares expected output with obtained output to verify that it executed correctly. Here's a simple example:

   def testExecute( self ):
       self.run()
       #
       # Checks that there were no error or warning messages:
       EDVerbose.DEBUG("Checking error messages...")
       EDAssert.equal( 0, self.getErrorMessages().getNumberObjects() )
       EDVerbose.DEBUG("Checking warning messages...")
       EDAssert.equal( 0, self.getWarningMessages().getNumberObjects() )
       #
       # Reads the obtained result and the expected result:
       strExpectedOutput = EDUtilsTest.readAndParseFile ( self.getReferenceOutputFile() )
       strObtainedOutput = EDUtilsTest.readAndParseFile( self.m_edObtainedOutputDataFile )

Note that self.m_edObtainedOutputDataFile and the value in self.getReferenceDataOutputFile() should be defined in the __init__ method. (Use method self.setReferenceDataOutputFile().)

Now the contents of strExpectedOutput and strObtainedOutput should be compared one by one. A simple example for the ISPyB data model:

       xsDataISPyBScreeningExpected = xsDataResultExpected.getScreeningStatus()
       xsDataISPyBScreeningObtained = xsDataResultObtained.getScreeningStatus()
       if xsDataISPyBScreeningExpected != None:
           EDVerbose.DEBUG("Checking screening ...")
           EDAssert.equal(xsDataISPyBScreeningExpected.getCode().getValue(), xsDataISPyBScreeningObtained.getCode().getValue())