Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
874 views
in Technique[技术] by (71.8m points)

java - 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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));
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...