2

I am new to junits. When I try to run my testsuite it is giving me this error. I googled but didn't get any answer. Posting the stacktrace.

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)

Here is the testsuite which I am trying to run.

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

}
R. Oosterholt
  • 7,720
  • 2
  • 53
  • 77
Prasad
  • 368
  • 1
  • 6
  • 16

4 Answers4

1

I discussed a similar problem in What is Junit trying to tell me when it throws a "NoTestsRemainException", the cause for me was an outdated JUnit jar of version 3.8 being loaded instead of the required JUnit 4.11.

Community
  • 1
  • 1
centic
  • 15,565
  • 9
  • 68
  • 125
0

Here is the working example for @Category (The example is from Java Doc). It works with my 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 {
 }

A main to call:

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

        /** Check results **/
    }
Maas
  • 1,317
  • 9
  • 20
0

The message is technically correct for your sample, but very misleading.

org.junit.runners.AllTests.class is not a valid parameter for @SuiteClasses (it is meant to be a JUnit 3.8 adapter) , so that the Categories runner discards it internally and then reports it has "no remaining tests" to run.

I suppose the incomplete error handling goes with the "experimental" part of the Java package for Categories, which is now deprecated by the new @Tag annotation in JUnit 5.

If you need to dynamically include all tests contained in classes in the classpath, try this thread: How do I Dynamically create a Test Suite in JUnit 4?

Denilson
  • 104
  • 5
0

A little bit late, but could be worth for someone

  1. Make sure you are using proper versions of libs. In my case junit-4.13.2, JUnit 5 = JUnit Platform 1.9.2 + JUnit Jupiter 5.9.2 + JUnit Vintage 5.9.2

  2. Annotation @Test is imported using org.junit.Test, not a org.junit.jupiter.api.Test

  3. Make all tests methods and class public

helvete
  • 2,455
  • 13
  • 33
  • 37
Jiri
  • 1
  • 1