Skip to content

JUnit tests defined in traits will crash the compiler with test.Test0.initializationError failed #7949

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

Closed
molikto opened this issue Jan 9, 2020 · 2 comments

Comments

@molikto
Copy link
Contributor

molikto commented Jan 9, 2020

minimized code

See this repo:

https://github.com/molikto/dotty-test

Compilation output
[error] Test test.Test0.initializationError failed: java.lang.Exception: Test class should have exactly one public constructor, took 0.002 sec
[error]     at com.novocode.junit.JUnitRunner$1.execute(JUnitRunner.java:124)
[error]     at sbt.TestRunner.runTest$1(TestFramework.scala:113)
[error]     at sbt.TestRunner.run(TestFramework.scala:124)
[error]     at sbt.TestFramework$$anon$2$$anonfun$$lessinit$greater$1.$anonfun$apply$1(TestFramework.scala:282)
[error]     at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:246)
[error]     at sbt.TestFramework$$anon$2$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:282)
[error]     at sbt.TestFramework$$anon$2$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:282)
[error]     at sbt.TestFunction.apply(TestFramework.scala:294)
[error]     at sbt.Tests$.$anonfun$toTask$1(Tests.scala:309)
[error]     at sbt.std.Transform$$anon$3.$anonfun$apply$2(System.scala:46)
[error]     at sbt.std.Transform$$anon$4.work(System.scala:67)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]     at sbt.Execute.work(Execute.scala:278)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]     at java.lang.Thread.run(Thread.java:834)
[debug] Test test.Test0.initializationError finished, took 0.006 sec
[debug] Test run finished: 1 failed, 0 ignored, 1 total, 0.008s

expectation

Traits should not be traited as a test class, changing traits to abstract class works.

@OlivierBlanvillain
Copy link
Contributor

I think you forgot to make your example repo public.

This doesn't look like a compiler crash, looking at the stack trace it's just JUnit complaining.

@sjrd
Copy link
Member

sjrd commented Jan 9, 2020

It's not a compiler crash, but it's a bug somewhere in the Dotty compiler (probably the ExtractAPI logic) or in the sbt plugin for Dotty. My analysis is that the sbt test detection code somehow detects that this trait is a valid test suite, and consequently asks JUnit to run the tests in that test suite. JUnit then crashes because it's an interface, not a concrete class.

Since the sbt test detection is based on its inc.Analysis, which itself is based on the API exported by ExtractAPI, I assume something's wrong that logic. Unless the sbt plugin for dotty computes test detection in a different way, in which case that logic could also be at fault (but I would be surprised if it does).

@smarter smarter closed this as completed in 3cbb5aa Jan 9, 2020
smarter added a commit that referenced this issue Jan 9, 2020
Fix #7949: sbt test discovery should not run traits
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

3 participants