990 likes | 1.94k Views
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
E N D
TestNG "Testing, the Next Generation“
Overview • Introduction • AboutTestNG • TestNG Features • Overview • Testmodell • Testconfiguration • ParametricTesting • XML Parameters • DataProvider • Annotations • @Test Annotation • ScopeAnnotations
Overview /2 • GettingStarted • JDK5 • JDK4 • IDE Integration / Plugins • Eclipse • Ant • Maven • Maven 1 • Maven 2 • Literatur • Q/A ?! • Live Demo
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
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.. ) • ….
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>
Testng.xml DTD Suite Parameters Test Parameters Classes / Class Include/exclude Methods Include/exclude Packages Include/exclude Include/exclude Groups Defines Runs Method-selectors
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>
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…; }
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) { …… }
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() { }
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“); }
Getting started – JDK4 import org.testng.Assert; Public class First { /** * @testng.test */ public void firstTest() { Assert.assertEquals(“1“,“1“); }
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)
Testng – Scope Annotations Class Suite Group Method Test
IDE Integration / Plugins • Eclipse Plugin – just like JUnit • Maven 1 – Plugin doesnt work • Maven 2 – works ok – with problems
Literatur • Next Generation Testing • Stefan Edlich, Mark Rambow • Entwickler Press (Oktober 2006) • www.testng.org • Forums.opensymphony.com/ forum.jspa?forumID=14
Questions ? Any Questions left?