views:

4425

answers:

3

I've made some unit tests (in test class). The tutorial I've read said that I should make a TestSuite for the unittests.

Odd is that when I'm running the unit test directly (selecting the test class - Run as jUnit test) everything is working fine, altough when I'm trying the same thing with the test suite there's always an exception: java.lang.Exception: No runnable methods.

Here is the code of the test suite:

import junit.framework.Test;
import junit.framework.TestSuite;

public class AllTests {

public static Test suite() {
 TestSuite suite = new TestSuite("Test suite for com.xxx.yyyy.test");
 //$JUnit-BEGIN$
 suite.addTestSuite(TestCase.class);
 //$JUnit-END$
 return suite;
    }

}

Any ideas why this isn't working ?

A: 

For sure, it won't work since you're not telling the test suite what are your test classes.

But I'm wondering why you're not using the "classical way" for building Test suites, which is ant using jUnit's ant tasks.

gizmo
+2  A: 

I'm not experienced in ant - so I'm not using it for testing it right now.

Searching the internet it seems like I'm mixing up the old jUnit 3.8 and jUnit 4.0 behavior. Trying now a way to use the "new behavior"

edited:
now it works:

AllTest changed to:

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


@RunWith(value=Suite.class)
@SuiteClasses(value={TestCase.class})
public class AllTests {

}

TestCase changed to:

import static org.junit.Assert.assertTrue;
import org.junit.Test;

public class TestCase  {
@Test
    public void test1 {
        assertTrue (tmp.getTermin().equals(soll));
    }
}
bernhardrusch
+1  A: 

Took me a bit too to figure it out, but I think this solves your problem:

You're doing a suite.addTestSuite(TestCase.class), while you should've done a suite.addTest(TestCase.class).

You can also add a testsuite to a testsuite to create a whole hierarchy of testsuites. In that case you'll have to use suite.addTest(). But note that you then use .suite() and not .class: suite.addTest(MyTestSuite.suite())!