1 / 19

TestNG

TestNG. "Testing, the Next Generation“. Overview. Introduction About TestNG TestNG Features Overview Testmodell Testconfiguration Parametric Testing XML Parameters DataProvider Annotations @Test Annotation Scope Annotations. Overview /2. Getting Started JDK5 JDK4

kmacdonald
Download Presentation

TestNG

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TestNG "Testing, the Next Generation“

  2. Overview • Introduction • AboutTestNG • TestNG Features • Overview • Testmodell • Testconfiguration • ParametricTesting • XML Parameters • DataProvider • Annotations • @Test Annotation • ScopeAnnotations

  3. Overview /2 • GettingStarted • JDK5 • JDK4 • IDE Integration / Plugins • Eclipse • Ant • Maven • Maven 1 • Maven 2 • Literatur • Q/A ?! • Live Demo

  4. Introduction • Founder: • Cédric Beust (Software Engineer @ Google Zürich) • Alexandru Popescu (ChiefArchitect @InfoQ.com) • Current Version: 5.5 • Created: 27. April 2004 • Last Update: 25. Januar 2007

  5. Features - Overview • JDK5 Annotations • Flexible Testconfiguration • Support for Data Driven testing • Introduction of Tests Granularities • Parallel Testing • Full JDK 1.4 Support (through JavaDoc Tags) • Full JUnit Support • Automatic TestSuite of failed Tests • TestScenarios and dependent Testing • Expected Exceptions (more than 1 per Method) • Easy to write Extension (own loggers, reporters etc.. ) • ….

  6. TestNG Testmodel

  7. Features - TestConfiguration testng.xml <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="testsuite"> <test verbose="1" name= "testname"> <packages> <package name= "test.*" /> </packages> <groups> <include name="groupsToRun"> </groups> </test> </suite>

  8. Testng.xml DTD Suite Parameters Test Parameters Classes / Class Include/exclude Methods Include/exclude Packages Include/exclude Include/exclude Groups Defines Runs Method-selectors

  9. Parametrisierte Tests – testng.xml In testng.xml: <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suitename=„dbsuite"> <parameter name="xls-path" value="conf/projects.xls" /> <parametername="db-driver" value="org.postgresql.Driver" /> <parametername="db-url" value="jdbc:postgresql://localhost:5432/postgres" /> <parametername="db-user" value="postgres" /> <parameter name="db-psswrd" value=“postgres" /> <test verbose="10" name=“database test"> <packages> <packagename="db.*" /> </packages> </test> </suite>

  10. Parametric Tests – testng.xml public class DatabaseFixture { @Parameters({ "xls-path", "db-driver", "db-url", "db-user", "db-psswrd"}) @BeforeTest public void retrieveDatabase(String path, String driver, String url, String user, String pssword) { Dbunit Methods inhere…; }

  11. Parametric Tests – @DataProvider • Fixed Args @DataProvider(name=“Prov“){ publicObject[][] provide() { returnnewObject[][] { { “String“, new Integer(10) }, { “String2“, new Integer(20) }, }; } @Test (dataProvider = “Prov“) Public voidtestSomethng(String string, Integer intgr) { …… }

  12. Parametric Tests – @DataProvider • Parametric DataProvider @DataProvider (name=“pDP“) { Public Object[][] createData(Method m) { if(m.getName().equals(“atest“)) { return new Object[][] {}} if(m.getName().equals(“btest“)) { return new Object[][] {}} } @Test (dataProvider=“pDP“) Public void atest() { }

  13. Getting started • Create POJO • Declare a Test withTestNG Annotation Import org.testng.annotation.Test; Import staticorg.testng.Assert.assertEquals; Public class First { @Test publicvoid firstTest() { assertEquals(“1“,“1“); }

  14. Getting started – JDK4 import org.testng.Assert; Public class First { /** * @testng.test */ public void firstTest() { Assert.assertEquals(“1“,“1“); }

  15. Testng - @Test Annotation • @Test (name=“example“, description=“exampletest“, expectedExceptions=IOException.class, dataProvider=“dataProv“, groups={“functional“,“stress“}, dependsOnGroups=“database“, dependsOnMethods={“init“,“setup“}, enabled=true, successPercentage=80, timeout=10000, invocationCount=10, threadPoolSize=10, sequential=true)

  16. Testng – Scope Annotations Class Suite Group Method Test

  17. IDE Integration / Plugins • Eclipse Plugin – just like JUnit • Maven 1 – Plugin doesnt work  • Maven 2 – works ok – with problems

  18. Literatur • Next Generation Testing • Stefan Edlich, Mark Rambow • Entwickler Press (Oktober 2006) • www.testng.org • Forums.opensymphony.com/ forum.jspa?forumID=14

  19. Questions ? Any Questions left?

More Related