maven - Suite Class not calling @BeforeClass & @AfterClass -
i have suite of test cases. want @beforeclass & @afterclass called before , after test case execution respectively. when run suite class using junit calls methods correctly, ie setup() called prior testcases , teardown() called after testcases completed.but when execute maven execute testcases , generate report using surefire not calling setup() & teardown()
@runwith(suite.class) @fixmethodorder(methodsorters.name_ascending) @suiteclasses({test1.class, test2.class}) public class suiteclass{ public static webdriver driver; public static string baseurl; public static stringbuffer verificationerrors = new stringbuffer(); @beforeclass public static void setup() throws exception { driver = new firefoxdriver(); baseurl = "http://localhost:7070/myproject/"; driver.manage().timeouts().implicitlywait(30, timeunit.seconds); } @afterclass public static void teardown() throws exception { driver.quit(); string verificationerrorstring = verificationerrors.tostring(); if (!"".equals(verificationerrorstring)) { fail(verificationerrorstring); } } }
finally found solution :) sharing others in need
suite class
@runwith(suite.class) @fixmethodorder(methodsorters.name_ascending) @suiteclasses({test1.class, test2.class}) public class suiteclass{ public static webdriver driver; public static string baseurl; public static stringbuffer verificationerrors = new stringbuffer(); @beforeclass public static void setup() throws exception { driver = new firefoxdriver(); baseurl = "http://localhost:7070/myproject/"; driver.manage().timeouts().implicitlywait(30, timeunit.seconds); } @afterclass public static void teardown() throws exception { driver.quit(); string verificationerrorstring = verificationerrors.tostring(); if (!"".equals(verificationerrorstring)) { fail(verificationerrorstring); } } }
entry in pom.xml report generation
<reporting> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-surefire-report-plugin</artifactid> <version>2.5</version> <configuration> <outputname>testreport</outputname> </configuration> </plugin> </plugins> </reporting>
specify maven goal execute suiteclass
site -dtest=com.test.testcase.suiteclass
Comments
Post a Comment