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.

Tests are not running in correct order if parallel="classes" is used with tests having dependsOnGroup and Priority

See original GitHub issue

TestNG Version

7.4.0

Expected behavior

image

Actual behavior

image

Is the issue reproducible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

package com.org.testng7;

import org.testng.annotations.Test;

public class Testng7{
	
	public Testng7() {
		// TODO Auto-generated constructor stub
	}

	@Test(groups = { "g1" }, priority = 1)
	public void t1() {
		System.out.println("Testng7:test 1" + " Thread ID: " + Thread.currentThread().getId());
	}

	@Test(groups = { "g2" }, dependsOnGroups = "g1", priority = 3)
	public void t2() {
		System.out.println("Testng7:test 2" + " Thread ID: " + Thread.currentThread().getId());
	}

	@Test(groups = { "g2" }, dependsOnGroups = "g1", priority = 2)
	public void t3() {
		System.out.println("Testng7:test 3" + " Thread ID: " + Thread.currentThread().getId());
	}

	@Test(groups = { "g2" }, dependsOnGroups = "g1", priority = 5)
	public void t4() {
		System.out.println("Testng7:test 4" + " Thread ID: " + Thread.currentThread().getId());
	}

	@Test(groups = { "g2" }, priority = 4)
	public void t5() {
		System.out.println("Testng7:test 5" + " Thread ID: " + Thread.currentThread().getId());
	}
}

// Another File

package com.org.testng7;

import org.testng.annotations.Test;

import com.kronos.testng.BaseUITest;

public class Testng7_copy{

	public Testng7_copy() {
		// TODO Auto-generated constructor stub
	}
	
	@Test(groups = { "g1" }, priority = 1)
	public void Testng7_copyt1() {
		System.out.println("Testng7_copy:test 1" + " Thread ID: " + Thread.currentThread().getId());
	}

	@Test(groups = { "g2" }, dependsOnGroups = "g1", priority = 3)
	public void Testng7_copyt2() {
		System.out.println("Testng7_copy:test 2" + " Thread ID: " + Thread.currentThread().getId());
	}

	@Test(groups = { "g2" }, dependsOnGroups = "g1", priority = 2)
	public void Testng7_copyt3() {
		System.out.println("Testng7_copy:test 3" + " Thread ID: " + Thread.currentThread().getId());
	}

	@Test(groups = { "g2" }, dependsOnGroups = "g1", priority = 5)
	public void Testng7_copyt4() {
		System.out.println("Testng7_copy:test 4" + " Thread ID: " + Thread.currentThread().getId());
	}

	@Test(groups = { "g2" }, priority = 4)
	public void Testng7_copyt5() {
		System.out.println("Testng7_copy:test 5" + " Thread ID: " + Thread.currentThread().getId());
	}
}

//Testng.xml file

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suites" parallel="classes" thread-count="2"
	configfailurepolicy="continue">

	<test name="Tests" >
		<groups>
			<run>
				<include name="g1" />
				<include name="g2" />
			</run>
		</groups>
		<classes>
			<class name="com.org.testng7.Testng7" />
			<class name="com.org.testng7.Testng7_copy" />
		</classes>

	</test>
</suite>

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:24

github_iconTop GitHub Comments

1reaction
juherrcommented, Sep 12, 2021

From what I see in the code, we use priority to sort the free nodes.

Sure but it is not expected. See the disabled tests: https://github.com/cbeust/testng/blob/master/testng-core/src/test/java/test/priority/PriorityTest.java

1reaction
juherrcommented, Sep 9, 2021

@krmahadevan I agree with your definition of soft/hard dependencies but it doesn’t explain why a soft dependency could not be respected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Parallel(methods) execution with dependsOn running in ...
A soft dependency is obtained by adding "alwaysRun=true" in your @Test annotation. For the dependsOnGroup example it reads. In this example, ...
Read more >
What are TestNG Dependent Tests and How to ... - Tools QA
Often, we want to run our test cases in a particular order in TestNG. We may use the priority parameter for that, no...
Read more >
Documentation - TestNG
By default, TestNG will run your tests in the order they are found in the XML file. ... If not set, default mechanism...
Read more >
testng not running in priority order when dependsOnMethods ...
The order of test execution should have been t1, t2, t3, t4. why is t4 getting executed after t1, when t2 and t3...
Read more >
Annotations - TestNG Docs
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the tag have run.
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