Skip to content

SBT is not finding JUnit tests #21

Closed
marcelinarcyz opened this Issue Jun 25, 2013 · 10 comments

7 participants

@marcelinarcyz

My build.sbt specifies the junit plugin:

libraryDependencies in ThisBuild += "com.novocode" % "junit-interface" % "0.10-M4" % "test"

The project has plenty of Java junit tests in the default {proj}/src/test/java that run fine when I use my Maven build.

Why would SBT not see my junit tests? Is there any way I can debug this?

The output I get:

[info] Loading global plugins from /home/devuser/.sbt/0.13.0-Beta2/plugins
[info] Set current project to myproj (in build file:/home/devuser/src/myproj/)
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
[info] No tests to run for myproj/test:test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
[info] No tests to run for myproj-subproja/test:test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
[info] No tests to run for myproj-subprojb/test:test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
[info] No tests to run for myproj-subprojc/test:test
[success] Total time: 0 s, completed Jun 23, 2013 8:01:41 AM

@marcelinarcyz

This issue was completely resolved when I turned on ConflictManager.strict and resolved all reported dependency conflicts.

@retronym
sbt member

I think there is a real issue here.

scala-async has test cases like:

@RunWith(classOf[JUnit4])
class Foo {
  @Test def bar() {
  }
}

These tests match two fingerprints that are handled by junit-interface.

Under SBT 0.13.x, SBT runs these under the JUnitFingerPrint, rather than the RunWithFingerPrint. The JUniteRunner.shouldRun then discards the tests.

Detected sbt version 0.13.0-RC5
Starting sbt: invoke with -help for other options
Using /Users/jason/.sbt/0.13.0-RC5 as sbt dir, -sbt-dir to override.
[info] Loading project definition from /Users/jason/code/scala-async/project
[info] Set current project to scala-async (in build file:/Users/jason/code/scala-async/)
> test-only scala.async.run.ifelse0.IfElseSpec
[info] Updating {file:/Users/jason/code/scala-async/}scala-async...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
testRunner
run()
cl = class scala.async.run.ifelse0.IfElseSpec
shouldRun(sbt.RunnerWrapper$1$4@397d812b, class scala.async.run.ifelse0.IfElseSpec)
JUNIT_FP.equals(fingerprint) = true
a.annotationType().equals(RunWith.class) = true
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[success] Total time: 1 s, completed Aug 14, 2013 1:57:57 PM

Applying this patch to junit-interface to change the order of the fingerprints:

   private static final Fingerprint[] FINGERPRINTS = new Fingerprint[] {
+    new RunWithFingerprint(),
     new JUnitFingerprint(),
-    new JUnit3Fingerprint(),
-    new RunWithFingerprint()
+    new JUnit3Fingerprint()
   };

SBT then uses the RunWithFingerprint.

> test-only scala.async.run.ifelse0.IfElseSpec
[info] Updating {file:/Users/jason/code/scala-async/}scala-async...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
testRunner
run()
cl = class scala.async.run.ifelse0.IfElseSpec
shouldRun(class sbt.RunnerWrapper$1$4, class scala.async.run.ifelse0.IfElseSpec)
JUNIT_FP.equals(fingerprint) = false
Running class scala.async.run.ifelse0.IfElseSpec
[info] Test run started
[info] Test scala.async.run.ifelse0.IfElseSpec.support await in a simple if-else expression started
[info] Test scala.async.run.ifelse0.IfElseSpec.await in condition started
[info] Test run finished: 0 failed, 0 ignored, 2 total, 0.031s
[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
[success] Total time: 1 s, completed Aug 14, 2013 1:58:58 PM

This seems to be tied to 363017c, which prevented a test that matched multiple finger prints from running more than once.

This change in SBT a0e301e3d8 now only runs a given test once (across all frameworks). I suspect that this doesn't include the backward compatibility measure used in an earlier incarnation of the same idea,

commit 24be2e5f25e288620b675f79e1dc4cd74c962f13
Author: Mark Harrah dmharrah@gmail.com
Date: Thu Dec 6 12:15:34 2012 -0500

Only make one call to test frameworks per test name.  Fixes #520.

- Requires selecting one fingerprint if there are more than one
- The selected fingerprint is by reverse ordering of Framework.tests
- Reverse ordering chosen to work with junit-interface without changes

/cc @harrah

@som-snytt

@retronym Thanks. I did my last contribution in your domain standalone with sbt in tdd mode, which was refreshing. Today I needed M5 and tried sbt.13 and suddenly I couldn't run a junit test.

@etorreborre etorreborre referenced this issue in playframework/playframework Oct 22, 2013
Merged

[2.2] Test results don't propagate to runner #1841

@huntc
huntc commented Oct 23, 2013

Hi @szeiger can we please have the issue re-opened? According to @retronym the issue still appears to be present and issue playframework/playframework#1841 has introduced some hackery to get around it (which should be removed once an appropriate fix has been implemented).

@richdougherty

BTW I created an issue to capture Play's specific problem: #30. Play is tracking the issue with Play#1889.

@benmccann

@jsuereth we might want to reopen this issue per @huntc 's request? unless @retronym you think it is it fixed by this recent commit? 7773353

@jsuereth
sbt member
jsuereth commented Jan 7, 2014

@benmccann Sure.

@jsuereth jsuereth reopened this Jan 7, 2014
@benmccann

Let's close this bug in favor of #30 which looks like a duplicate of this one and provides a great test case to reproduce. It looks like this is fixed in SBT 0.13.6-M1 as I commented on the other bug

@benmccann

Let's close this bug now

@richdougherty

Reported fixed: #30 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.