mardi 3 avril 2018

Enabling running single test for each input managed by for loop in java using testng framework

I want to send inputs that are being produced by the baseTestBeforeTest() method for each of the input which invoked in runTestSuite() method (that will be the unit testing method), in other words: how can i use a loop in order to send different output to my test methods for each iteration of the loop?

@BeforeTest
    public void baseTestBeforeTest() throws Exception {

        String cageInstanceIp = Configuration.prop.getProperty("suite.pusher.defaultParams.cageInstanceIp");

        addingAllFilesToList();

        int size = this.files.size();
        System.out.println("number of session to be run are: " + size);
        for(int i=0;i<size;i++){

                System.out.println("-------------------------------------------------------------------------------------------------------------------------");
                System.out.println("running test for the following json input file: " + this.files.get(i));
                System.out.println("-------------------------------------------------------------------------------------------------------------------------");
                this.list=this.runHelperForTestsPreparationMethods.runHelperPreparation(this.files.get(i), this.list);
                if(i==size-1){
                    isLast=true;
                }
                runTestSuite();
        }

      }

This is runTestSuite() method:

@Test
    public void runTestSuite() throws Exception {
       this.runHelperForTestsPreparationMethods.testCompareJsonPercentage(this.isLast);
          testCompareJsonPercentage(isLast);

    }

But what I get is that after the for loop is done and running tests as expected for each input it then goes right away again to runTestSuite() method as part of the logic of TestNG, I want to be able to not face this issue and to run base test and test (unit testing) for each input.

I searched the network for solution but did not find any...

Aucun commentaire:

Enregistrer un commentaire