1

I am trying to create a junit test suite that will run all of the test suites within the application... - this is what I have and as far as I can find it should work but it keeps telling me that no tests are found.

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * @author Jason
 *
 */

@Test
public class applicationTest extends TestCase {

    public applicationTestSuite(String name) {
        super(name);
    }

    public static Test suite() {
        TestSuite suite = new TestSuite("ApplicationTestSuite");
        suite.addTest(domain.AllDomainTests.suite());
        suite.addTest(services.AllServicesTests.suite());
        suite.addTest(business.AllBusinessTests.suite());
        return suite;
    }
}

An example of one of the test suites it should be running -

package business;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({ ItemMgrTest.class })
public class AllBusinessTests {

}

2 Answers 2

1

You need to mark @Test annotation on test method

API Document

The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case. To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method. Any exceptions thrown by the test will be reported by JUnit as a failure. If no exceptions are thrown, the test is assumed to have succeeded [...]

1
  • The individual test suites run fine on their own... it is the aggregate test suite that is not working.
    – Expecto
    Jun 17, 2012 at 18:26
0

You can specify Suite classes in your @SuiteClasses, for instance:

@RunWith(Suite.class)
@SuiteClasses({ AllBusinessTests.class })
public class AllTests {

}

The suite() method is a JUnit 3 thing, and won't find any methods or tests in your suite, because you're using JUnit 4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.