Hello! I have a question regarding Scalatest 3.1.0...
# general
s
Hello! I have a question regarding Scalatest 3.1.0+ on PANTS 1.30 Everything was working fine with Scalatest 3.0.8, but now, having it bumped to 3.1.0 (or 3.2.0, it does not matter), we are experiencing the following issues:
Copy code
11:01:39 00:12       [run]
                     Auto-detected 32 processors, using -parallel-threads=32
                     .E.E.E.E
                     Time: 0.021
                     There were 4 failures:
                     1) initializationError
                     java.lang.NullPointerException
                     	at __shaded_by_pants__.org.pantsbuild.tools.junit.impl.ScalaTestUtil.getJUnitRunner(ScalaTestUtil.java:62)
                     	at __shaded_by_pants__.org.pantsbuild.tools.junit.impl.CustomAnnotationBuilder$ScalaTestAnnotatedBuilder.runnerForClass(CustomAnnotationBuilder.java:52)
                     	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 __shaded_by_pants__.org.pantsbuild.tools.junit.impl.AnnotatedClassRequest.getRunner(AnnotatedClassRequest.java:41)
                     	at __shaded_by_pants__.org.pantsbuild.tools.junit.impl.CompositeRequestRunner.runChild(CompositeRequestRunner.java:53)
                     	at __shaded_by_pants__.org.pantsbuild.tools.junit.impl.ConcurrentCompositeRequestRunner$1$1.run(ConcurrentCompositeRequestRunner.java:37)
                     	at __shaded_by_pants__.org.pantsbuild.tools.junit.impl.ConcurrentRunnerScheduler.finished(ConcurrentRunnerScheduler.java:89)
                     	at __shaded_by_pants__.org.pantsbuild.tools.junit.impl.ConcurrentCompositeRequestRunner$1.evaluate(ConcurrentCompositeRequestRunner.java:46)
                     	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
                     	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
                     	at __shaded_by_pants__.org.pantsbuild.tools.junit.impl.ConsoleRunnerImpl.runLegacy(ConsoleRunnerImpl.java:613)
                     	at __shaded_by_pants__.org.pantsbuild.tools.junit.impl.ConsoleRunnerImpl.run(ConsoleRunnerImpl.java:503)
                     	at __shaded_by_pants__.org.pantsbuild.tools.junit.impl.ConsoleRunnerImpl.main(ConsoleRunnerImpl.java:790)
is it something that just needs some additional configuration which we are missing currently?
e
@square-oxygen-75288 can you supply your exact prior scalatest dependency and the exact current one? Do you have an explicit dependency on scalatestplus? If so can you provide those before and after as well?
l
Do you use Junit annotation in your scalatests?
s
@loud-stone-83419 no, we just
extend FlatSpec
everywhere. No annotations. Test targets look something like
Copy code
junit_tests(
  name='foo',
  sources=['./foo/*.scala'],
  dependencies=[
    ':specs'
  ]
)
l
I believe in the latest version of scalatest you are required to add annotations to your code if you want to use the Junit test runner
So that's not compatible as is with pants anymore
Made a Scalatest plugin for pants 1.30 I could share the code but unfortunatly this is not open source
also it is still a very much work in progress
so would be use at your own risks
s
@enough-analyst-54434 current is (3rdparty/BUILD)
Copy code
jar_library(name='scalatest',
            jars=[
              scala_jar(org='org.scalatest', name='scalatest', rev='3.2.0')
            ])
jar_library(name='scalacheck',
            jars=[
              scala_jar(org='org.scalatestplus', name='scalacheck-1-14', rev='3.2.0.0'),
              scala_jar(org='com.github.alexarchambault', name='scalacheck-shapeless_1.14', rev='1.2.0')
            ])
prior was
Copy code
jar_library(name='scalatest',
            jars=[
              scala_jar(org='org.scalatest', name='scalatest', rev='3.0.8')
            ])
jar_library(name='scalacheck',
            jars=[
              scala_jar(org='org.scalacheck', name='scalacheck', rev='1.14.0'),
              scala_jar(org='com.github.alexarchambault', name='scalacheck-shapeless_1.14', rev='1.2.0')
            ])
we have a target to bring it all together
Copy code
target(
  name='specs',
  dependencies=[
    '3rdparty:scalatest',
    '3rdparty:scalamock',
  ]
)
and the junit target is
Copy code
junit_tests(
  name='foo',
  sources=['./foo/*.scala'],
  dependencies=[
    ':specs'
  ]
)
e
s
@enough-analyst-54434 I tried to define it like
Copy code
jar_library(name='scalatest',
            jars=[
              scala_jar(org='org.scalatest', name='scalatest', rev='3.2.3'),
              scala_jar(org='org.scalatestplus', name='scalacheck-1-15', rev='3.2.3.0'),
              scala_jar(org='org.scalatestplus', name='junit-4-13', rev='3.2.3.0')
            ])
it did not help
am I doing it wrong?
e
Hmm, well - at a lower level I'm checking this with:
Copy code
$ coursier fetch org.scalatestplus:junit-4-13_3.0.0-M3:3.2.3.0
/home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalatestplus/junit-4-13_3.0.0-M3/3.2.3.0/junit-4-13_3.0.0-M3-3.2.3.0.jar
/home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3.0.0-M3/3.0.0-M3/scala3-library_3.0.0-M3-3.0.0-M3.jar
/home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-core_3.0.0-M3/3.2.3/scalatest-core_3.0.0-M3-3.2.3.jar
/home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/junit/junit/4.13/junit-4.13.jar
/home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.4/scala-library-2.13.4.jar
/home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalactic/scalactic_3.0.0-M3/3.2.3/scalactic_3.0.0-M3-3.2.3.jar
/home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalatest/scalatest-compatible/3.2.3/scalatest-compatible-3.2.3.jar
/home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_2.13/1.2.0/scala-xml_2.13-1.2.0.jar
/home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
$ zipinfo -1 /home/jsirois/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalatestplus/junit-4-13_3.0.0-M3/3.2.3.0/junit-4-13_3.0.0-M3-3.2.3.0.jar | grep JUnitRunner
org/scalatestplus/junit/JUnitRunner.class
org/scalatestplus/junit/JUnitRunner.tasty
So I used coursier directly which required me to fill in the scala release in the artifact id:
org.scalatestplus:junit-4-13_3.0.0-M3:3.2.3.0
- Are you in fact using scala 3.0.0-M3? That's the only scalatestplus-junit artifact I can find on maven central.
s
I have added a minimal reproduction repo: https://github.com/slvrtrn/pants-1.30-junit-scalatest-issue And yes, @enough-analyst-54434 you were right: it works well with the annotation.
We are using Scala 2.12 and not 3.x
e
OK, for 2.12 I only find:
org.scalatestplus:junit-4-12_2.12:3.2.0.0
with coursier, so you probably need:
scala_jar(org='org.scalatestplus', name='junit-4-12', rev='3.2.0.0')
s
it is resolved fine anyway..
the thing is, I still need to add this explicit annotation which was not the case with Scalatest 3.0.8
l
Unfortunately that is because of scalatest - pants is just the proxy
s
I am curious why
org.scalatestplus.junit.JUnitRunner
cannot be loaded (and a NPE is thrown)... it is available in the classpath, as I can add the annotation like
Copy code
@RunWith(classOf[JUnitRunner])
see it in my repo: https://github.com/slvrtrn/pants-1.30-junit-scalatest-issue/blob/main/test/scala/com/github/slvrtrn/TestHello.scala#L3-L20 but john.sirois provided the sources of failure https://github.com/pantsbuild/pants/blob/a7b1a5ab1800ecac561a5c3b5ff2be7b9f58a2c0/src/java/org/pantsbuild/tools/junit/impl/ScalaTestUtil.java#L[…]63 and https://github.com/pantsbuild/pants/blob/a7b1a5ab1800ecac561a5c3b5ff2be7b9f58a2c0/src/java/org/pantsbuild/tools/junit/impl/ScalaTestUtil.java#L[…]20 in the latter,
Copy code
junitRunnerClass = Class.forName("org.scalatestplus.junit.JUnitRunner");
seems to be the correct one! so what is the problem then?..
e
Thanks for the example repo. That makes it a whole lot easier to track down. Fix demonstrated here: https://github.com/slvrtrn/pants-1.30-junit-scalatest-issue/pull/1
It turns out the scalatestplus-junit jar needs to be included in the
junit
BUILD.tools so that Pant's junit-runner tool can still see the scalatestplus class after shading.
❤️ 2
s
@enough-analyst-54434 thanks a lot!! we will try it out