views:

40

answers:

2

Howdy,

I have 2 test classes, both extend TestCase. Each class contains a bunch of individual tests which run against my program.

How can i execute both classes (and all tests they have) as part of the same suite?

I am using jUnit 4.8

Thank you

+1  A: 

Create TestClass and override suite() method and run newly created TestClass.

 public static Test suite()
    {
        TestSuite suite = new TestSuite("Test ExpenseTest");
        suite.add(TestCase1.class);
        suite.add(TestCase2.class);
        return suite;
    }
VinAy
Is this how jUnit 4 does it?
mac
Maybe this JavaDoc will help http://kentbeck.github.com/junit/javadoc/4.8/org/junit/runners/Suite.html. I have never used it JavaDoc have enough information
VinAy
+1  A: 

In jUnit4 you have something like this:

@RunWith(Suite.class)
@SuiteClasses({
    SomeTest.class,
    SomeOtherTest.class,
    ...
    })
public class AllTests {}

If you want the Eclipse GUI suite builder (New > JUnit Test suite), you have to add

public static junit.framework.Test suite() {
   return new JUnit4TestAdapter(SomeTest.class);
}

to each of your test classes s.t. the GUI test suite builder recognizes your test.

Juri