I've clubbed feature related tests in one test class. Suppose we've 50 tests in that class.
Out of 50, suppose there are 5 test cases which require common test data or pre-requisites.
If I create/set it in setup method of class like @BeforeClass
annotation of TestNG and delete/reset
in tear down method like @AfterClass
, it has following drawbacks -
- If I want to run single test or tests, which does/do not belong to those 5 tests, still it'll perform create/set operations which are irrelevant to this test.
- Also it confuses new tester which data is for which tests. Unnecessarily makes him to think what
@BeforClass
is doing for all following tests. - If data/set up only required for specific tests, system should be retain to earlier state after those tests are executed. This statement also fails here.
Is following better approach to handle this -
Even though 5 tests require same setup and test data, we should create/set it for each test and remove/reset it after that test is run.
But this also has drawback - this will increase execution time.
Please suggest what is best approach used in such cases.
NOTE: These five test cases are such that those cannot be handled with data provider.