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; @Test(groups = {"FirstTest"}) public class Test1 { public void init(){
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>
source share