Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUnit4TestAdapter blocks JUnit-3-style suites that are included via @RunWith(Suite.class) #1189

Closed
mkeller opened this issue Aug 12, 2015 · 0 comments

Comments

@mkeller
Copy link

mkeller commented Aug 12, 2015

The intention of junit.framework.JUnit4TestAdapter is to allow a JUnit-3-style test runner to run JUnit-4-style tests.

However, due to a bug in JUnit, this doesn't work when a JUnit-4-style test suite (@RunWith(Suite.class)) includes a JUnit-3-style suite class.
Happened to us in https://bugs.eclipse.org/bugs/show_bug.cgi?id=474777

To reproduce in JUnit itself:

  • remove the @RunWith(AllTests.class) annotation from org.junit.tests.junit3compatibility.OldTests
  • run the whole org.junit.tests.AllTests:
    • if you run it with a JUnit-4-style runner, it passes
    • but with a JUnit-3-style runner that calls the suite() method, it fails with:
AllTests (org.junit.tests)
org.junit.tests.AllTests
org.junit.tests.junit3compatibility.OldTests
initializationError(org.junit.tests.junit3compatibility.OldTests)
java.lang.Exception: No runnable methods
    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:202)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:138)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:68)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:101)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:87)
    at org.junit.runners.Suite.<init>(Suite.java:102)
    at org.junit.runners.Suite.<init>(Suite.java:70)
    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:501)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:108)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:40)
    at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:34)
    at org.junit.tests.AllTests.suite(AllTests.java:246)
...

I'm preparing a pull request.

mkeller added a commit to mkeller/junit that referenced this issue Aug 12, 2015
mkeller added a commit to mkeller/junit that referenced this issue Aug 14, 2015
mkeller added a commit to mkeller/junit that referenced this issue Aug 17, 2015
kcooney pushed a commit to kcooney/junit that referenced this issue Jul 17, 2016
kcooney pushed a commit to kcooney/junit that referenced this issue Jul 17, 2016
@kcooney kcooney closed this as completed in 25495b3 Oct 8, 2016
@kcooney kcooney modified the milestone: 4.13 Aug 6, 2017
sebasjm pushed a commit to sebasjm/junit4 that referenced this issue Mar 11, 2018
…that are included via @RunWith(Suite.class) (junit-team#1344)

* Fixes junit-team#1189: JUnit4TestAdapter blocks JUnit-3-style suites that are included via @RunWith(Suite.class)

* Redo fix of 1189 in a way that won't break code that subclasses AllDefaultPossibilitiesBuilder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants