JUnit and junit.framework.TestSuite - No runnable methods

后端 未结 4 1221
别跟我提以往
别跟我提以往 2020-12-21 00:46

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 tes

相关标签:
4条回答
  • 2020-12-21 01:34

    Be careful when using an IDE's code-completion to add the import for @Test. It has to be import org.junit.Test and not import org.testng.annotations.Test, for example. If you use the second one by mistake, you'll get the "no runnable methods" error. (I was using Intellij Idea 2017 which imported org.junit.jupiter.api.Test instead!)

    0 讨论(0)
  • 2020-12-21 01:40

    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));
        }
    }
    
    0 讨论(0)
  • 2020-12-21 01:45

    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.

    0 讨论(0)
  • 2020-12-21 01:51

    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())!

    0 讨论(0)
提交回复
热议问题