Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit and junit.framework.TestSuite - No runnable methods

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 ?

like image 409
bernhardrusch Avatar asked Oct 10 '08 05:10

bernhardrusch


People also ask

What is Testsuite in JUnit?

Test suite is used to bundle a few unit test cases and run them together. In JUnit, both @RunWith and @Suite annotations are used to run the suite tests. This chapter takes an example having two test classes, TestJunit1 & TestJunit2, that run together using Test Suite.

How JUnit testing works?

JUnit provides static methods to test for certain conditions via the Assert class. These assert statements typically start with assert. They allow you to specify the error message, the expected and the actual result. An assertion method compares the actual value returned by a test to the expected value.

What is JUnit library used for?

JUnit is a Java unit testing framework that's one of the best test methods for regression testing. An open-source framework, it is used to write and run repeatable automated tests.


1 Answers

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));
    }
}
like image 60
bernhardrusch Avatar answered Oct 20 '22 09:10

bernhardrusch