views:

54

answers:

1

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.

+2  A: 

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
The Alchemist
Thank you for your answer. Is there a way I can see that screenshot from behind something more corporate firewall friendly...? Or perhaps just some annotation would be great, thanks!
Zombies
@Zombies: I can email it to you. It's just a screenshot of what it looks like in Eclipse when you run a suite.
The Alchemist
@the-alchemist: Ah. I see. I think the problem is that Eclipse is not finding the Unit tests (the class which has the suites.) Eclipse is also not finding the TestSuite.
Zombies
@Zombies: That's really strange. It should. You can also try manually setting up a run configuration through `Run->Run Configurations->JUnit`. What version of Eclipse do you use? Every version of Eclipse that supports JUnit 4 recognizes classes with `@RunWith(Suite.class)`.
The Alchemist
@the-alchemist: Helios. I think I had to set the package of the "AllTests" test suite that I was to be creating to the same with the tests in it for them to show. I also needed to rename the tests to start with "test" in the method.
Zombies