testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.98k stars 1.02k forks source link

Issues with dependsOnMethods and Priority being used simultaneously #474

Closed drarghya closed 7 years ago

drarghya commented 10 years ago

Hi, I have a scenario where I have 6 test methods that need executed in order. The first one in the order depends on another test method, and the last method in the order also depends on a different test method. So in total there are 6 tests.

Here's the example:

    @Test(priority = 1)
    public void initiateSetup(){        
        if(setupTests.equals("")){
            ReportGenerator.logTest("Setup", "SKIPPED - This test has been skipped", reportMap, REPORT_NAME);
            throw new SkipException ("Skipping Test: " + this.testId);
        }
        else
            System.out.println("RUNNING SETUP...");
            Assert.assertTrue((!setupTests.equals("")));
    }

    @Test(priority = 2, dataProvider = "feeder", threadPoolSize = 1, invocationCount = 1, dependsOnMethods = {"initiateSetup"})
    @Source(tempSetupDataFile)
    public void setupTest() throws NumberFormatException, MalformedURLException, java.text.ParseException, InterruptedException
    {

        executeSetupTest();
    }

    @Test(priority = 3)
    public void initiateTests(){
        System.out.println("RUNNING TESTS...");
    }

    @Test(priority = 4, dataProvider = "feeder", threadPoolSize = 1, invocationCount = 1)
    @Source(tempTestDataFile)
    public void runTest() throws NumberFormatException, MalformedURLException, java.text.ParseException, InterruptedException
    {   
        executeTest();
    }

    @Test(priority = 5)
    public void initiateTeardown(){     
        if(teardownTests.equals("")){
            ReportGenerator.logTest("Teardown", "SKIPPED - This test has been skipped", reportMap, REPORT_NAME);
            throw new SkipException ("Skipping Test: " + this.testId);
        }
        else
            System.out.println("RUNNING TEARDOWN...");
            Assert.assertTrue((!teardownTests.equals("")));
    }

    @Test(priority = 6, dataProvider = "feeder", threadPoolSize = 1, invocationCount = 1, dependsOnMethods = {"initiateTeardown"})
    @Source(tempTeardownDataFile)
    public void teardownTest() throws NumberFormatException, MalformedURLException, java.text.ParseException, InterruptedException
    {
        executeTeardownTest();
    }

Now this sequence works fine when I remove the dependsOnMethods attribute from the setupTest and teardownTest methods. The moment I add it back, the sequence goes for a toss, it executes initiateSetup, runTest, initiateTeardown, setupTest, teardownTest in this order. I thought this was fixed in a previous release, isn't that the case ?

I am using TestNG testng-6.2.1.jar

huyto commented 10 years ago

this issue works as design as test has dependsOnMethods attribute will execute last to prevent creating cycles with priority.

arghya commented 10 years ago

The question is how does it work when I run it from eclipse and why not when I execute it from the command as a jar file ?

huyto commented 10 years ago

I used v6.8.7 and it works the same for me in eclipse and in command line. But it's possible it works different in eclipse and command line as the eclipse plugin point to the testng.jar inside the plugin which could have different version than the one run on the command line.

ghost commented 10 years ago

@huyto How to update testng.jar in eclipse plugin?

juherr commented 8 years ago

http://stackoverflow.com/q/39330510/4234729

juherr commented 7 years ago

Fixed by https://github.com/cbeust/testng/pull/1158