Extructure of UnitTest

Asked by Reinaldo Burgos

Hi,

Are any of you in this forum that know how to structure UnitTest, testsuite and setup/tearDown in the correct way?

If I create the following structure:

allTest.py
def suite():
  return unittest.TestSuite([
                              unittest.TestLoader().loadTestsFromTestCase(A_test.ATestCase)
                            , unittest.TestLoader().loadTestsFromTestCase(B_test.BTestCase)
                            , unittest.TestLoader().loadTestsFromTestCase(C_test.CTestCase)
                            ])
if __name__ == '__main__':
  unittest.TextTestRunner().run(suite())

A_test.py
class ATestCase(TestInit):
        def test_build_uri_abs(self):

        def test_build_uri_rel(self):

        def test_build_uri_rel_slashless(self):

B_test.py
classBTestCase(TestInit):
        def test_build_uri_abs(self):

        def test_build_uri_rel(self):

        def test_build_uri_rel_slashless(self):

C_test.py
class CTestCase(TestInit):
        def test_build_uri_abs(self):

        def test_build_uri_rel(self):

        def test_build_uri_rel_slashless(self):

Init.py
class TestInit(unittest.TestCase):

    def setUp(self):
        global ffApp
        ffLoc = r'C:\Program\Mozilla Firefox\firefox.exe'
        ffTitle = "Mozilla Firefox"
        ffApp = App(ffTitle) # app object "containing" all FF windows
        if not ffApp.window():
            print("open firefox..")
            App(ffLoc).focus() # opens FF
            wait(4)
        ffApp.focus()
        print("type zaci url..")
        type('l', KEY_CTRL)
        paste('https://localhost/index.php')
        type(Key.ENTER)
        wait("1381231580670.png", 20)
        with Region(find("1381231618344.png")):
            doubleClick("1381231634958.png")
            type("hudson")
            wait(2)
            doubleClick("1381231649319.png")
            type("hudson1")
            wait(2)
            click("1381231658482.png")
        wait("1381231705529.png", 10)

    def tearDown(self):
        print("Close Firefox")
        click("Loggaut.png")
        wait(2)
        ffApp.close()
        wait(5)

Any comment and feedback will appreciated.

//RB

Question information

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

Besides the fact, that needed imports are missing (by intention?), this looks ok.

So what is the question?

Revision history for this message
Reinaldo Burgos (reinaldo-burgos-y) said :
#2

Every time I run the project, the the setUp() and tearDown() methods call for every test case but the testcases does'nt run.
Why?

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

besides not having divided the stuff into separate .py, this does what it should:

import unittest

class TestInit(unittest.TestCase):
    def setUp(self):
        print "setup"

    def tearDown(self):
        print "teardown"

class Test1(TestInit):
    def test_11(self):
        print "test11"
        assert True

    def test_12(self):
        print "test12"
        assert True

    def test_13(self):
        print "test13"
        assert True

class Test2(TestInit):
    def test_21(self):
        print "test21"
        assert True

    def test_22(self):
        print "test22"
        assert True

    def test_32(self):
        print "test23"
        assert True

suite = unittest.TestSuite((
        unittest.TestLoader().loadTestsFromTestCase(Test1),
        unittest.TestLoader().loadTestsFromTestCase(Test2),
        ))
unittest.TextTestRunner().run(suite)

--- output
......
----------------------------------------------------------------------
Ran 6 tests in 0.001s

OK

setup
test11
teardown
setup
test12
teardown
setup
test13
teardown
setup
test21
teardown
setup
test22
teardown
setup
test23
teardown

Can you help with this problem?

Provide an answer of your own, or ask Reinaldo Burgos for more information if necessary.

To post a message you must log in.