HTML reporting on multiple suites

Asked by Alan Dale

Sorry if this has been answered already but I’ve searched and couldn’t find the answer to this.

I’ve got several test scripts set up as suites that I am trying to call from a main test script. I can call them and run them but the reporting doesn’t come out as expected. I get an overlap of the 2 test suites. Is this possible in Sikuli? I feel I am close but can’t quite get the right results. My goal is to be able to run multiple suites from one main script. I’m new to programming and python so go easy :)

Any advice would be great

My code looks like this:

testScriptA.Sikuli

from sikuli import*
import unittest
import HTMLTestRunner

class UnitTestA(unittest.TestCase):
 def setup(self):
  test code

 def teardown(self):
  test code

 def someTest(self):
  test code

testScriptB.Sikuli

from sikuli import*
import unittest
import HTMLTestRunner

class UnitTestB(unittest.TestCase):
 def setup(self):
  test code

 def teardown(self):
  test code

 def someTest(self):
  test code

mainTest.sikuli

import unittest
from UnitTestA import*
from UnitTestB import*

suite1=unittest.TestLoader().loadTestsFromTestCase(UnitTestA)
suite2=unittest.TestLoader().loadTestsFromTestCase(UnitTestB)
unittest.TextTestRunner(verbosity=2).run(suite)
outfile = open("C:\Report.html", "wb")
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='Xbox Test Report', description='This is a demo' )
runner.run(suite1)
runner.run(suite2)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

# --- testScriptA.Sikuli

from sikuli import*
import unittest
# import HTMLTestRunner # to be deleted, not needed here

class UnitTestA(unittest.TestCase):
 def setup(self):
  test code

 def teardown(self):
  test code

 def someTest(self):
  test code

# --- testScriptB.Sikuli

from sikuli import*
import unittest
# import HTMLTestRunner # to be deleted, not needed here

class UnitTestB(unittest.TestCase):
 def setup(self):
  test code

 def teardown(self):
  test code

 def someTest(self):
  test code

# --- mainTest.sikuli

import unittest

from UnitTestA import *
from UnitTestB import *

import HTMLTestRunner # needed here

suite=unittest.TestLoader().loadTestsFromTestCase(UnitTestA) # setup new test suite
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(UnitTestB)) # add additional test cases

# unittest.TextTestRunner(verbosity=2).run(suite) # not needed, since you wantant to run HTMLTestRunner

outfile = open("C:\Report.html", "wb")

runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='Xbox Test Report', description='This is a demo' )
runner.run(suite)

outfile.close()

# more comments
--- one test script.sikuli may contain as many unit test classes as needed
(since loading/adding the test cases references the class name, not the module name)

--- normally no need to have more than one suite

--- if you make changes to the test classes, besides the need to save them, you have to restart the IDE, before running the mainTest again. Since mainTest should be rather fixed, you could run it from command line and have the test case script open in IDE as long you are changing code (only saving needed).

As a workaround, to be able to rerun, you can use:
import some_module
reload(some_module)
from some_module import *
So you can make changes in some_module and rerun the main script without restarting the IDE.

--- with the above sequence of imports, it is sufficient to have all your scripts in one directory (testScriptA.sikuli, testScriptB.sikuli, mainTest.sikuli and HTMLTestRunner.py), since with import, the .sikuli will be searched for in the current directory and after this, this current directory is in sys.path, so HTMLTestRunner will be found too.

Revision history for this message
Alan Dale (adale3g) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
Alan Dale (adale3g) said :
#3

Excellent!

"suite.addTests" fixed everything!

I'm running everything from command line so i'm only using the IDE to make changes to scripts.

Thanks for the help! :)

Revision history for this message
nupur (nupur) said :
#4

Hi,

I also have a similar problem.
I have created 2 Test Scripts and 1 main script where these 2 test scripts are getting called.
If I change in one test script and even after saving it does not reflect in main script.
I also have used:
 import some_module
 reload(some_module)
 from some_module import *
in main method but after every change I have to save as the script with other name then only the changes are reflecting in main script.

Is there any other way to save changes and also getting reflected in main script???

Revision history for this message
RaiMan (raimund-hocke) said :
#5

@ nupur
when asking questions via comments to even solved questions, you have to subscribe (done this for you this time ;-), to get notified about reactions.

-- your problem
I do not dare to ask:
have you substituted some_module with the names of your scripts?
Needed for every module to be used.

from some_module import *
only needed if you want to use names from module without qualification (not recommended with unitttesting).
some_function() instead of some_module.some_function()

Revision history for this message
nupur (nupur) said :
#6

Ofcouse Yes!! I hv replaced some_module with my test script name.
Now wat exactly i hv to write to import latest changes of any test script??

Not yet clear :(

Revision history for this message
RaiMan (raimund-hocke) said :
#7

@nupur

--- Now wat exactly i hv to write to import latest changes of any test script??

exactly how it is written above:

supposing you have a TestA.sikuli in the same directory as your Main.sikuli.

# in Main.sikuli
import TestA
reload(TestA)

and the later you can say:
suite=unittest.TestLoader().loadTestsFromTestCase(TestA.UnitTestA)

supposing the test class in TestA is called UnitTestA.

The rest is standard Python stuff.