lundi 18 janvier 2021

Should integration tests be independent?

I'm writing integration tests for a web application using Selenium. In a past project, I have created a single test function which tested all the features of the app. An example in Python using unittest:

class TestWebUI(unittest.Testcase)
    def test_app(self):
        login("admin")
        testListX()
        x = testCreateX()
        testCreateY(x)
        testUpdateX()
        testUpdateY()
        testDeleteX()
        testDeleteY()
        testCreateZ()

        login("user")
        testListX()
        testListY()
        testCreateZ()         

In this previous project, a developer should only submit a patch if the big monolithic test (and its subtests) passed. To be sure, the tests would also run in a server when any patch was submitted in a server; the results would be displayed in the patch review tool and a patch could only be approved if all tests passed. This worked fine.

I'm on a new project and considered replacing the monolithic integration tests with smaller tests. However, that will require adding setup code (and therefore will require extra execution time) for each test. For instance, the test code above would become something like:

class TestWebUI(unittest.TestCase):
    def test_list_x(self):
        login("admin")
        (testListX() code here)

    def test_create_x(self):
        login("admin")
        (testCreateX() code here)

    def test_delete_x(self):
        login("admin")
        (create dummy x)
        (testDeleteX() code here)

    def test_create_y(self):
        login("admin")
        (create dummy x)
        (testCreateY(x) code here)

What are the benefits of the latter approach, besides the possibility of running tests concurrently? Is it common to split integration tests into several tests and duplicate test setup for each one?

This question mentions specific technologies such as Selenium, Python and unittest, but it is independent from them.

Aucun commentaire:

Enregistrer un commentaire