TestNG - Gestione dei gruppi di test

E' anche possibile definire dei gruppi nei test. Così si possono realizzare test divisi per : 'unit test', 'integration test' ecc.

Ciò può essere realizzato tramite l'annotazione @Test e con il parametro 'groups'.




package it.testng.samplegroup.test;

import org.testng.annotations.Test;


public class SampleGroupTest {

@Test(groups = {"gruppo 1", "gruppo 2"})
public void TestMethod1() {
System.out.println("Metodo 1");
}

@Test(groups = {"gruppo 2"})
public void TestMethod2() {
System.out.println("Metodo 2");
}

@Test(groups = {"gruppo 3"})
public void TestMethod3() {
System.out.println("Metodo 3");
}

}




e configurando il file testNg.xml aggiungendo :


<test name="TestGroup">
<groups>
<run>
<include name="gruppo 2" />
</run>
</groups>
<classes>
<class name="it.testng.samplegroup.test.SampleGroupTest" />
</classes>
</test>



E' anche possibile escludere dai test un gruppo

inserendo all'interno di il tag
es:


Si può realizzare anche una gerarchia dei gruppi



@Test(groups = { "main" })
public class All {

@Test(groups = { "little" )
public void method1() { ... }

public void method2() { ... }
}


il method2 riferisce al gruppo "main" invece il method1 viene eseguito per i test di "main" che quelli di "little"

Nessun commento: