Zombies
Zombies

Reputation: 25912

How can I use TestSuites with Junit4?

I can't seem to find any documentation on how to do this that actually explains how to invoke the testsuite. So far I have this:

package gov.hhs.cms.nlr.test;

import java.util.LinkedList;   
import org.junit.runner.RunWith;    
import gov.hhs.cms.nlr.test.marshalling.InquiryMarshallingTest;
import junit.framework.Test;
import junit.framework.TestSuite; 
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

public class AllTests {

    @RunWith(Suite.class)
    @Suite.SuiteClasses({
        SomeTestTest.class
        SomeOtherTest.class
    })

    public class AllSuites {
        // the class remains completely empty, 
        // being used only as a holder for the above annotations
    }    
}

However I do not really understand how I can run this... What I want to do is take all given tests (each test, and from each Class which has Test methods) and put these all into 1 TestSuite and then invoke that.

Update: I would like to know how to run this in (1) Eclipse and (2) hudson and (3) plain java/JVM invocation (eg: java ...). Thank you.

Upvotes: 1

Views: 282

Answers (1)

The Alchemist
The Alchemist

Reputation: 3425

I think you want something like this:

package gov.hhs.cms.nlr.test;

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

@RunWith(Suite.class)
@SuiteClasses({OtherTest.class, SomeTestTest.class})
public class AllTests 
{

}

Much simpler... It gives you this:

screenshot of Eclipse running test suite

Running in Eclipse

You run it just like a regular JUnit class: Run->Run As->JUnit Test.

Running in Hudson

Depends how you are running your build. Ant? Maven?

Running from Java

Check out the JUnit FAQ. Basically:

java org.junit.runner.JUnitCore gov.hhs.cms.nlr.test.AllTests

Upvotes: 2

Related Questions