Sto provando a creare due test in cui uno dipende dall'esecuzione dell'altro. Il progetto a cui sto lavorando è pieno di codice legacy, quindi sto provando a rendere testabili le parti principali dell'applicazione. Il primo test proverà fondamentalmente a creare una connessione a un database e a impostare alcune variabili statiche. Test2 utilizzerà quindi la connessione e le variabili per inserire alcuni dati. Preferirei non fare le cose che Test1 fa ancora una volta in Test2.Il metodo dipende dal gruppo inesistente - Testng
Ho reso Test2 dipendente da test1 in modo che se Test1 non riesce, Test2 non verrà eseguito. Ma se Test2 fallisce, voglio che sia in grado di rieseguire. Quando provo questo in Intellij IDEA ottengo il seguente:
java.lang.Throwable: Method a.stack.Test2.failingTest() depends on nonexistent group "FirstTest"
Cosa mi manca?
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);
}
}
E 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>
Funziona alla prima esecuzione, ma quando Test2 non riesce e faccio una replica dei test falliti lancia il throwable che indica che il gruppo, FirstTest, non esiste. – user1213843