question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues with dependsOnMethods and Priority being used simultaneously

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:6

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

TestNg using dependsOnMethods and priority violates priority
Don't provide priority and depends on together, you can group the tests. You can do it like : @Test(priority = 1, groups =...
Read more >
combined hard and soft dependencies in single @Test?
Use a group but put @Test(alwaysRun=true) on the shutDownService...maybe? ... I have been experimenting with the "priority" argument, but I don't
Read more >
Top 50+ TestNG Interview Questions and Answers for 2022
Ans: Priority is an attribute that tells TestNG which orders have to follow to run test method. It is used to set the...
Read more >
Documentation - TestNG
dependsOnMethods, The list of methods this method depends on. ... Note: this attribute used to be called sequential (now deprecated).
Read more >
A Quick JUnit vs TestNG Comparison - Baeldung
In the previous JUnit 4 version, we would need to use the @Before and ... A suite is a collection of test cases...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found