mercredi 6 septembre 2017

TestNG Automation Framework running tests individually, locally

I am a beginner in TestNG. I am currently working in a company where they have a homegrown api automation framework. I am used to running my test case in isolation when local and using Cucumber. However, things are very tightly coupled in this framework. Let me give a briefing on different aspects of the framework:

Test Data Management: Test data are read through properties file. All the test case data are listed in the properties using key values per api module. The way the keys are numbered are by testcase type and a counter attached to it. So for example:

example.properties

.....
.....
    getTestCase38=TC_ID_38
    getDescription38= Description_38
    getUserID38=<some value>
    getUserType38=<some value>
    expectedUserType38=<some value>

    getTestCase39=TC_ID_39
    getDescription39= Description_39
    getUserID39=<some value>
    getUserType39=<some value>
    expectedUserType39=<some value>

    postTestCase1=TC_ID_1
    postDescription1= Description_1
    postUserID1=<some value>
    postUserType1=<some value>
    expectedUserType1=<some value>
...
...

Test Data Flow: The data is read from the properties file. A property file maps to a TestNG class. The naming convention of these methods in a TestNG class are as follows:

public class ModuleA extends ModuleACommon{    

int getcount = 0;
int postcount = 0;

    @Test(priority=20)
    public void testMoudleAGetPositive38(){
     callMethodToReadData(getcount++);
     ....
    }   

    @Test(priority=21)
    public void testModuleAGetPositive39(){
     callMethodToReadData(getcount++);
     ....
     ....
    } 
    ......
    ......

    @Test(priority=30)
    public void testModuleAPostPositive1(){
     callMethodToReadData(postcount++);
     ....
     ....
    }   
   ......
   ......
}

Note that when callMethodToReadData is called the count is incremented and it is used to build the key to access the test data from the properties file. The test cases are set to a priority in sequential order, this ensures that the proper key is constructed. This is painful because if I want to add a new test case following this pattern. Lets say I want to add a test case and assign it a priority of 21 then I will have to adjust the priority for all the test methods after 21 including the 21st priority test case.

For short term: I am trying to find an easiest way to run one test in isolation. There are dirty ways of accomplishing this. For example, I can just comment out other test case and reassign the appropriate count values but this is too inefficient.

Long Term: I would love to hear opinions and suggestions to improve this in the long run. I have couple of ideas myself for long term improvements, however I was hoping to get more insightful suggestions from here.

Also, let me know if there are any hacks that could solve the problem of adding test cases and not having to reorganize the priorities (I have a solution that I have already implemented where I just use a unique key that is more descriptive of the actual test case).

Aucun commentaire:

Enregistrer un commentaire