Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.test;
- import org.junit.AfterClass;
- import org.junit.BeforeClass;
- import org.junit.runner.RunWith;
- import org.junit.runners.Suite;
- import org.junit.runners.Suite.SuiteClasses;
- @RunWith(Suite.class)
- @SuiteClasses({Test1.class, Test2.class})
- public class TestSuite {
- @BeforeClass
- public static void setUp() {
- System.out.println("setting up");
- }
- @AfterClass
- public static void tearDown() {
- System.out.println("tearing down");
- }
- }
- package com.test;
- import org.junit.Test;
- public class Test1 {
- @Test
- public void test1() {
- System.out.println("test1");
- }
- }
- setting up
- test1
- test2
- tearing down
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.5</version>
- <configuration>
- <includes>
- <include>**/*Suite.java</include>
- </includes>
- <excludes>
- <exclude>**/*Test.java</exclude>
- <exclude>**/*Tests.java</exclude>
- </excludes>
- </configuration>
- </plugin>
- import junit.framework.Test;
- import junit.framework.TestResult;
- import junit.framework.TestSuite;
- public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("TestEverything");
- //$JUnit-BEGIN$
- suite.addTestSuite(TestOne.class);
- suite.addTestSuite(TestTwo.class);
- suite.addTestSuite(TestThree.class);
- //$JUnit-END$
- }
- public static void main(String[] args)
- {
- AllTests test = new AllTests();
- Test testCase = test.suite();
- TestResult result = new TestResult();
- setUp();
- testCase.run(result);
- tearDown();
- }
- public void setUp() {}
- public void tearDown() {}
- }
- public class AbstractTest {
- private static int nbTests = listClassesIn(<package>).size();
- private static int curTest = 0;
- @BeforeClass
- public static void incCurTest() { curTest++; }
- @AfterClass
- public static void closeTestSuite() {
- if (curTest == nbTests) { /*cleaning*/ }
- }
- }
- public class Test1 extends AbstractTest {
- @Test
- public void check() {}
- }
- public class Test2 extends AbstractTest {
- @Test
- public void check() {}
- }
- import org.junit.*;
- import static org.junit.Assert.*;
- import java.util.*;
- class SomethingUnitTest {
- @BeforeClass
- public void runBeforeClass()
- {
- }
- @AfterClass
- public void runAfterClass()
- {
- }
- @Before
- public void setUp()
- {
- }
- @After
- public void tearDown()
- {
- }
- @Test
- public void testSomethingOrOther()
- {
- }
- }
Add Comment
Please, Sign In to add comment