• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Devoxx test ng
 

Devoxx test ng

on

  • 1,218 views

 

Statistics

Views

Total Views
1,218
Views on SlideShare
1,215
Embed Views
3

Actions

Likes
1
Downloads
21
Comments
0

3 Embeds 3

https://twimg0-a.akamaihd.net 1
http://a0.twimg.com 1
https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • JUnit (créé en 1997) 4.0 est sorti en début 2006, introduction de @Test Junit est une déesse égyptienne :o) (Iounyt)
  • JUnit : @Rule TestWatcher (TestWatchman deprecated)

Devoxx test ng Devoxx test ng Presentation Transcript

  • TestNGParce que vos tests le valent bien ! Romain Linsolas @romaintaz 1
  • Abstract• TestNG, kézako ?• Parlons fonctionnalités… 2
  • Romain Linsolas•Développeur Java / Web depuis 2002•Éleveur dusines logicielles•@ Société Générale @romaintaz http://linsolas.free.fr/wordpress 3
  • 1. Présentation 4
  • Test « New Generation » http://testng.org/ https://github.com/cbeust/testng• Créé par Cédric Beust (Google) en avril 2004• Version 6.5.1 1.0 2.0 4.0 5.0 6.0 6.5 2004 2005 2006 2007 2008 2009 2010 2011 2012 5
  • Support IDE / buildersNatif Par plugin 6
  • 2. Fonctionnalités Parce quil y en a plein dedans ! 7
  • @Test (non parce que c’est une librairie de tests quand même)expectedExceptions Méthode ou classetimeOut dependsOnMethods / dependsOnGroup expectedExceptionsMessageRegExp groups dataProvider invocationCount, singleThreaded threadPoolSize priority 8
  • @Annotations@BeforeMethod / @AfterMethod @BeforeTest / @AfterTest@BeforeClass / @AfterClass @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) @Testpublic 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
  • IAnnotationTransformerIAnnotationTransformer2IHookableIInvokedMethodListenerIMethodInterceptorIReporterISuiteListenerITestListener 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 dautres choses… Logger inclus Rapports de résultats (xml, html) Support Guice Support du YAML Rerun failing tests first Peut lancer du JUnit 3.x 25
  • 26
  • Questions… 27