java - JUnit run suite -
i wrote maven-junit project run through eclipse.
have package 5 classes:
1. junittest1.java
2. junittest2.java
3. adapter.java,
4. junittestsuite.java
5. testrunner.java
the code in junittestsuite class
import org.junit.runner.runwith; import org.junit.runners.suite; import org.junit.runners.suite.suiteclasses; @runwith(suite.class) @suiteclasses({ junittest1.class, junittest2.class }) public class junittestsuite { }
the code in testrunner class is:
import org.junit.runner.junitcore; import org.junit.runner.result; import org.junit.runner.notification.failure; public class testrunner { public static void main(string[] args) { result result = junitcore.runclasses(junittestsuite.class); (failure failure : result.getfailures()) { system.out.println(failure.tostring()); } system.out.println(result.wassuccessful()); } }
when run project junit test, there 4 test running, 2 tests under suite , each of tests separately; meaning each test ran twice. suggestions how run suite?
thanks!
orit
if using maven don't need testrunner class. can introduce suite class maven in pom.xml this:
<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-surefire-plugin</artifactid> <version>2.17</version> <configuration> <argline>-xmx3g</argline> <includes> <include>**/junittestsuite.java</include> </includes> </configuration> </plugin>
it run suite class , test classes not run twice.
Comments
Post a Comment