JUnit: how to avoid “no runnable methods” in test utils classes

后端 未结 10 684
清酒与你
清酒与你 2020-11-30 05:35

I have switched to JUnit4.4 from JUnit3.8. I run my tests using ant, all my tests run successfully but test utility classes fail with \"No runnable methods\" error. The patt

相关标签:
10条回答
  • 2020-11-30 06:03

    I was also facing a similar issue ("no runnable methods..") on running the simplest of simple piece of code (Using @Test, @Before etc.) and found the solution nowhere. I was using Junit4 and Eclipse SDK version 4.1.2. Resolved my problem by using the latest Eclipse SDK 4.2.2. I hope this helps people who are struggling with a somewhat similar issue.

    0 讨论(0)
  • 2020-11-30 06:06

    Annotate your util classes with @Ignore. This will cause JUnit not to try and run them as tests.

    0 讨论(0)
  • 2020-11-30 06:06

    To prevent JUnit from instantiating your test base class just make it

    public abstract class MyTestBaseClass { ... whatever... }
    

    (@Ignore reports it as ignored which I reserve for temporarily ignored tests.)

    0 讨论(0)
  • 2020-11-30 06:06

    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 do the latter, you'll get the "no runnable methods" error.

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