Devoxx test ng

Preview:

DESCRIPTION

 

Citation preview

1

TestNGParce que vos tests le valent

bien !Romain Linsolas

@romaintaz

2

Abstract

•TestNG, kézako ?

•Parlons fonctionnalités…

3

Romain Linsolas

•Développeur Java / Web depuis 2002

•Éleveur d'usines logicielles

•@ Société Générale

@romaintaz

http://linsolas.free.fr/wordpress

1. Présentation

4

Test « New Generation »

•Créé par Cédric Beust (Google) en avril 2004

•Version 6.5.1

5

http://testng.org/

https://github.com/cbeust/testng

6.56.06.05.05.0

201220112010200920082007200620052004

4.04.02.02.01.01.0

Support IDE / buildersNatif Par plugin

6

2. Fonctionnalités

Parce qu'il y en a plein dedans !

7

@Test(non parce que c’est une librairie de tests quand même)

expectedExceptions

timeOut

Méthode ou classe

dependsOnMethods / dependsOnGroup

expectedExceptionsMessageRegExp

groups

dataProvider

invocationCount, singleThreaded threadPoolSize

priority

8

@Annotations

@BeforeMethod / @AfterMethod

@BeforeClass / @AfterClass

@BeforeTest / @AfterTest

@BeforeSuite / @AfterSuite

@BeforeGroups / @AfterGroups

9

Groupes de tests

10

@Test(groups = { "non-regression" })

public class MonTest {

@Test(groups = { "slow",  "integration" })

public void sloooooowTest() { ... }

@Test(groups = { "fast" })

public void fastTest() { ... }

11

Avec JUnit…

@Category(Integration.class) @Test

public void unTest { ... }

@RunWith(Categories.class)

@IncludeCategory(IntegrationTest.class)

@SuiteClasses({ Test1.class, Test2.class })

public class IntegrationTestSuite { }

12

java org.testng.TestNG -groups non-regression

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-surefire-plugin</artifactId>

<configuration>

<groups>non-regression</groups>

</configuration>

</plugin>

13

Dépendances de tests

14

public class MonTest {

@Test

public void deployOnTomcat() { ... }

@Test(dependsOnMethods = {"deployOnTomcat"})

public void testWebUI() { ... }

@Test(dependsOnGroups= {"integration.*"})

public void someDependentTests() { ... }

15

public class MonTest {

@Test

public void firstTest() { ... }

@Test(dependsOnMethods = {"firstTest"},

alwaysRun = true)

public void secondTest() { ... }

16

Les Listeners

17

@Test @Listeners(MonListener.class)

public class maClasseDeTests { ... }

public class MonListener implements ITestListener {

public void onTestFailure(ITestResult res) { ... }

public void onFinish(ITestContext cxt) { ... }

18

IAnnotationTransformer

IAnnotationTransformer2

IHookable

IInvokedMethodListener

IMethodInterceptor

IReporter

ISuiteListener

ITestListener

19

Tests paramétrés

20

@Test @Parameters({ "db" })

public void monTest(String db) { … }

<suite name="ma-suite">

<parameter name="db" value="oracle"/>

<test name="monTest"/>

21

@DataProvider(name = "mon-provider")

public Object[][] getObjects() {

return new Object[][] {

{ 1, 1 }, { 5, 120 }

};

}

@Test(dataProvider = "mon-provider")

public void testFactorielle(int valeur, int resultat) {

assertEquals(resultat, App.factorielle(valeur));

}

22

Les Factories

23

public class TestNGFactory {

private String foo;

public TestNGFactory(String foo) { this.foo = foo; }

@Factory public Object[] factory() {

return new Object[] {

new TestNGFactory("hello"),

new TestNGFactory("Devoxx") };

}

@Test public void test() {

System.out.println("==> " + foo);

}

}

24

Et plein d'autres choses…

25

Support du YAML

Rapports de résultats(xml, html)

Logger inclus

Rerun failing tests first

Support Guice

Peut lancer du JUnit 3.x

26

Questions…

27