junit-interface
junit-interface copied to clipboard
sbt 0.13.1 and junit-interface 0.10 doesn't run JUnit tests
I have a project where we have lots of unit tests written. We've recently upgraded to sbt 0.13 and now our unit tests don't run. If I add the following to my build.sbt:
crossPaths := false
then it picks up the tests and runs successfully.
I built my own version of the plug-in and put in some debugging statements and then turned on global debugging within the build.sbt and it appears that the JUnitRunner is never even instantiated when crossPaths is defaulted to true.
Sorry, my observation seems to be a red herring. I'm having trouble reproducing things, which leads me to believe that my IDE and SBT are working at cross-purposes.
If it's of any value - this worked for me: I had a multi-module project with one pure java module (with only JUnit tests), and I couldn't get sbt to run this module's JUnit tests until I set crossPaths := false
for this module.
Just chiming in - this also worked for me. Scala 2.11.7 SBT 0.13.8 java sources and java junit tests won't run without "crossPaths := false"
Thanks for the crossPaths
hint.
I've been able to solve this:
http://stackoverflow.com/questions/28174243/run-junit-tests-with-sbt/34490115#34490115
Looks like I had the same problem, but running on sbt 0.13.8 but scala 2.10.4 and "com.novocode" % "junit-interface" % "0.11"
and I had to disable crossPaths
as well before the JUnit Tests were detected.
loadedTestFrameworks
showed the JUnit Testrunner, but the test files themselves were not shown in definedTests
.
Digged a bit deeper and the effect of switching the property crossPaths
is that the compile
task returns slightly different objects. In the sbt.inc.MAnalysis
object the apis.internal
HashMap contains tuples containing my test files, however in the case of crossPaths := true
the value xsbti.api.Source
contains nothing under api.definitions
, which is what Tests.discover
reduces all entries to.
I found that while SBT 0.13.16 does not run JUnit tests that have crossPaths := false
, SBT 1.0.1 DOES run them. Both with junit-interface
0.11, on the same build file.
I just happened across this issue trying to understand why my JUnit tests stopped running when I moved from SBT 1.2.8 to 1.3.13 (both with junit-interface 0.11).
It turns out the crossPaths := false
solution also works in the case of SBT 1.3.. I'll open another issue linking to this one with the heading "SBT 1.3. and junit-interface 0.11 not running JUnit tests" to help anyone searching in the future.
So I've had a similar issue on coursier/interface. There is an interface-test module that has java test and runs them using the junit-interface plugin.
crossPaths := false
also fixed this for me, but more importantly, tests were still not running on the JVM 17.
On JVM 11:
env JAVA_HOME="/Users/David.Francoeur/Library/Caches/Coursier/arc/https/github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.14.1%252B1/Ope
nJDK11U-jdk_x64_mac_hotspot_11.0.14.1_1.tar.gz/jdk-11.0.14.1+1/Contents/Home" sbt "interface-test/test"
[info] welcome to sbt 1.5.8 (Eclipse Adoptium Java 11.0.14.1)
[info] loading global plugins from /Users/David.Francoeur/.sbt/1.0/plugins
[info] loading settings for project coursier-interface-build-build-build from metals.sbt ...
[info] loading project definition from /Users/David.Francoeur/workspace/dev/coursier-interface/project/project/project
[info] loading settings for project coursier-interface-build-build from metals.sbt ...
[info] loading project definition from /Users/David.Francoeur/workspace/dev/coursier-interface/project/project
[success] Generated .bloop/coursier-interface-build-build.json
[success] Total time: 1 s, completed Jun. 2, 2022, 10:02:56 a.m.
[info] loading settings for project coursier-interface-build from metals.sbt,plugins.sbt ...
[info] loading project definition from /Users/David.Francoeur/workspace/dev/coursier-interface/project
[success] Generated .bloop/coursier-interface-build.json
[success] Total time: 1 s, completed Jun. 2, 2022, 10:02:58 a.m.
[info] loading settings for project coursier-interface from build.sbt ...
[info] set current project to coursier-interface (in build file:/Users/David.Francoeur/workspace/dev/coursier-interface/)
[info] ProGuard, version 7.2.1
[info] Warning: can't write resource [META-INF/services/coursier.jniutils.NativeApi] (Duplicate jar entry [META-INF/services/coursier.jniutils.NativeApi])
[info] Warning: can't write resource [LICENSE] (Duplicate jar entry [LICENSE])
[info] Warning: can't write resource [NOTICE] (Duplicate jar entry [NOTICE])
[info] compiling 4 Java sources to /Users/David.Francoeur/workspace/dev/coursier-interface/interface-test/target/test-classes ...
[error] Test coursierapi.test.VersionsTests.simple failed: java.lang.NullPointerException: null, took 0.263 sec
[error] at coursierapi.shaded.coursier.core.compatibility.package$$anon$1.label(package.scala:161)
[error] at coursierapi.shaded.coursier.maven.MavenRepository.$anonfun$fetchVersions$3(MavenRepository.scala:275)
[error] ...MORE TEST LOG HERE
[error] ... 54 more
[error] Failed: Total 6, Failed 5, Errors 0, Passed 1
[error] Failed tests:
[error] coursierapi.test.CompleteTests
[error] coursierapi.test.VersionsTests
[error] coursierapi.test.FetchTests
[error] (interface-test / Test / test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 30 s, completed Jun. 2, 2022, 10:03:31 a.m.
where as with jvm 17, nothing runs:
env JAVA_HOME="/Users/David.Franc
oeur/jvm/temurin/jdk-17.0.2-8/Contents/Home" sbt "interface-test/test"
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by sbt.TrapExit$ (file:/Users/David.Francoeur/.sbt/boot/scala-2.12.14/org.scala-sbt/sbt/1.5.8/run_2.12-1.5.8.jar)
WARNING: Please consider reporting this to the maintainers of sbt.TrapExit$
WARNING: System::setSecurityManager will be removed in a future release
[info] welcome to sbt 1.5.8 (Eclipse Adoptium Java 17.0.2)
[info] loading global plugins from /Users/David.Francoeur/.sbt/1.0/plugins
[info] loading settings for project coursier-interface-build-build-build from metals.sbt ...
[info] loading project definition from /Users/David.Francoeur/workspace/dev/coursier-interface/project/project/project
[info] loading settings for project coursier-interface-build-build from metals.sbt ...
[info] loading project definition from /Users/David.Francoeur/workspace/dev/coursier-interface/project/project
[success] Generated .bloop/coursier-interface-build-build.json
[success] Total time: 0 s, completed Jun. 2, 2022, 10:03:56 a.m.
[info] loading settings for project coursier-interface-build from metals.sbt,plugins.sbt ...
[info] loading project definition from /Users/David.Francoeur/workspace/dev/coursier-interface/project
[success] Generated .bloop/coursier-interface-build.json
[info] compiling 4 Scala sources to /Users/David.Francoeur/workspace/dev/coursier-interface/project/target/scala-2.12/sbt-1.0/classes ...
[success] Total time: 3 s, completed Jun. 2, 2022, 10:03:59 a.m.
[info] loading settings for project coursier-interface from build.sbt ...
[info] set current project to coursier-interface (in build file:/Users/David.Francoeur/workspace/dev/coursier-interface/)
[info] compiling 1 Scala source and 30 Java sources to /Users/David.Francoeur/workspace/dev/coursier-interface/interface/target/scala-2.13/classes ...
[warn] 1 deprecation (since 2.0.0-RC6-15)
[warn] 32 deprecations (since 2.13.0)
[warn] 33 deprecations in total; re-run with -deprecation for details
[warn] three warnings found
[info] ProGuard, version 7.2.1
[info] Warning: can't write resource [META-INF/services/coursier.jniutils.NativeApi] (Duplicate jar entry [META-INF/services/coursier.jniutils.NativeApi])
[info] Warning: can't write resource [LICENSE] (Duplicate jar entry [LICENSE])
[info] Warning: can't write resource [NOTICE] (Duplicate jar entry [NOTICE])
[info] compiling 4 Java sources to /Users/David.Francoeur/workspace/dev/coursier-interface/interface-test/target/test-classes ...
[success] Total time: 13 s, completed Jun. 2, 2022, 10:04:14 a.m.
The code in question is there, may you be interested: https://github.com/daddykotex/interface/tree/cfdd00a2b059584dfc4f6a917603849a340e2a9c