running junit tests with scalatest in sbt

385 views
Skip to first unread message

Imran Rashid

unread,
Jan 15, 2015, 6:30:17 PM1/15/15
to scalate...@googlegroups.com
Is it possible to have the scalatest runner in sbt also run junit tests?

The section in the scalatest docs about junit:
http://www.scalatest.org/getting_started_with_junit_4_in_scala

is about doing the opposite: writing your tests in scala w/ scalatest, but running with junit. I have the opposite problem: I have a codebase which has some tests written in Java using junit, and I'd like to have sbt run those junit tests via the scalatest runner.

The reason I want this is from my attempt to exclude IntegrationTests with a test tag. It means that I run my tests with something like:

test-quick * -- -l testTag

We've been running those tests using the junit-interface plugin for sbt:
https://github.com/sbt/junit-interface

It seems like all those args after "--" are passed to both test runners. From the junit-interface docs: "Any parameter not starting with - or + is treated as a glob pattern for matching tests."  Which means that the testTag for scalaTest ends up becoming a glob pattern for the junit interface, and so all junit tests are skipped.

Fundamentally the difference in the way the args work between the junit-interface and the scalatest runner seem like it is going to create big problems with a project that uses tests written with both junit & scalatest.

There is another question of how to do the equivalent of test tags in our junit tests, but it seems like we can probably do the same thing with junit categories or something.

(If you are really curious, I'm messing with this for Apache Spark, you can track the issue here:
)

thanks
Imran

Imran Rashid

unread,
Jan 16, 2015, 8:25:47 PM1/16/15
to scalate...@googlegroups.com
I've come up with another way to do what I want, but with a small patch to scalatest.

Inside sbt, I call testQuick once for scalatest, and once more for junit.  However, I can't get sbt to call one runner in each case -- it calls both each time, I just have to dupe the other runner to do nothing.

This is easy to do for the junit runner, since any unrecognized arg is treated as a pattern on the tests.

But for scalatest, its trickier, since it throws an exception on any arg it doesn't recognize.  I have a patch so that if there is the arg "--scalatest-please-do-nothing" it doesn't run any tests and ignores the rest of the args.  Pretty hacky.

I've posted a question on stack overflow, hopefully the sbt folks will suggest something better: https://stackoverflow.com/questions/27995197/how-do-i-get-sbt-test-to-only-call-scalatest-or-junit-tests-inside-a-custom-ta

but if there is no other alternative, I can submit my patch (perhaps with better naming ...)
Reply all
Reply to author
Forward
0 new messages