当我尝试运行我的junits时获取NoTestsRemainException

时间:2014-07-24 11:44:48

标签: java junit selenium-webdriver webdriver junit4

我是junits的新手。当我尝试运行我的测试套件时,它给了我这个错误。我用Google搜索但没有得到任何答案。发布堆栈跟踪。

org.junit.runner.manipulation.NoTestsRemainException
at org.junit.runners.ParentRunner.filter(ParentRunner.java:327)
at org.junit.experimental.categories.Categories.<init>(Categories.java:151)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:35)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

这是我试图运行的测试套件。

@RunWith(Categories.class)
@Categories.IncludeCategory(DCCTests.class)
@SuiteClasses({ AllTests.class })
public class DealerCommandCenterTestsSuite {

}

3 个答案:

答案 0 :(得分:1)

我在What is Junit trying to tell me when it throws a "NoTestsRemainException"中讨论了一个类似的问题,我的原因是加载了一个过时的JUnit jar版本3.8而不是所需的JUnit 4.11。

答案 1 :(得分:0)

以下是@Category的工作示例(该示例来自Java Doc)。它适用于我的JUnit 4.11

org.junit.experimental.categories.Categories

public interface FastTests {
 }

 public interface SlowTests {
 }

 public static class A {
    @Test
    public void a() {
        fail();
    }

    @Category(SlowTests.class)
    @Test
    public void b() {
    }
 }

 @Category( { SlowTests.class, FastTests.class })
 public static class B {
    @Test
    public void c() {

    }
 }

 @RunWith(Categories.class)
 @IncludeCategory(SlowTests.class)
 @SuiteClasses( { A.class, B.class })
 // Note that Categories is a kind of Suite
 public static class SlowTestSuite {
 }

主要致电:

public static void main(String[] args)
    {
        Result result  = JUnitCore.runClasses(SlowTestSuite.class);

        /** Check results **/
    }

答案 2 :(得分:0)

该消息在技术上对您的样本是正确的,但非常误导。

org.junit.runners.AllTests.class不是@SuiteClasses的有效参数(它应该是一个JUnit 3.8适配器),因此Categories运行器会在内部丢弃它,然后报告它有&#34; no剩下的测试&#34;跑。

我认为不完整的错误处理与&#34;实验&#34;类别的Java包的一部分,现在JUnit 5中新的@Tag注释已弃用。

如果需要动态地包含类路径中类中包含的所有测试,请尝试以下线程:How do I Dynamically create a Test Suite in JUnit 4?