Method depends on non-existent group - Testng

I am trying to create two tests in which one depends on the execution of the other. The project I'm working on is filled with legacy code, so I'm trying to test the main parts of the application. The first test will basically try to create some database connection and set some static variables. Then Test2 will use the connection and variables to insert some data. I would rather not do what Test1 does again in Test2.

I made Test2 dependent on test1, so if Test1 fails, Test2 will not run. But if Test2 fails, I want it to be able to try again. When I try this in Intellij IDEA, I get the following:

java.lang.Throwable: Method a.stack.Test2.failingTest() depends on nonexistent group "FirstTest" 

What am I missing?

Test1:

 package a.stack; import org.testng.Assert; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; /** * The First test */ @Test(groups = {"FirstTest"}) public class Test1 { public void init(){ // Initialize something which other tests should use Assert.assertTrue(true); } } 

And Test2:

 package a.stack; import org.testng.Assert; import org.testng.annotations.Test; /** * */ @Test(groups = {"OtherTests"}, dependsOnGroups = {"FirstTest"}) public class Test2 { public void failingTest(){ Assert.assertTrue(false); } } 

Testng.xml:

 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="test" verbose="1"> <test name="basic" junit="false"> <groups> <run> <include name="FirstTest"/> <include name="OtherTests"/> </run> </groups> <packages> <package name="a.*"/> </packages> </test> </suite> 
+7
source share
3 answers

Are you sure that the package you specified contains methods in this group?

0
source

If the test does not run in the package, then the testng-failed.xml file is created in the output directory, which is used to restart failed cases. Can you check this file to make sure that the xml file contains both groups and not only other tests that really failed?

  <run> <include name="FirstTest"/> <include name="OtherTests"/> </run> 

Because if it does not have a FirstTest group, then the error depends on nonexistent group "FirstTest" .

0
source

Your group code is incorrect in testng.xml as it must contain the package name

  <groups> <run> <include name="packagename.FirstTest"/> <include name="packagename.OtherTests"/> </run> </groups> 

then include your classes with the package name after the group tags [this is optional since you are already using the package name]

  <class name="packagename.classname1"/> <class name="packagename.classname2"/> 

The code should work now

0
source

Source: https://habr.com/ru/post/908618/


All Articles