szeiger/junit-interface — Issue #8: JUnit interface seems not to find all JUnit tests written in Scala
Author: bnord01
Created: 2012-02-22 10:58:27+00:00
State: open

I have a rather big Scala project with JUnit tests written in Scala which I used to build with Maven but I thought I would give SBT a trie. Sadly the JUnit interface doesn't seem to find any of the more involved tests in the src/test/scala folder. Even though they are compiled properly. I thought it could have something to do with the fact that I use the @BeforeClass annotation in the companion object of the individual tests.

I couldn't reproduce the exact problem with a minimal example. In the example I came up with sbt seems to generate a random number X for the line.

[info] Passed: : Total X, Failed 0, Errors 0, Passed X, Skipped 0

Even though all tests produce output.

Here's the setup and output:

./build.sbt

name := "sbt junit test project"

version := "1.0"

scalaVersion := "2.9.1"

libraryDependencies += "com.novocode" % "junit-interface" % "0.8" % "test"

./src/test/scala/Test1.scala

import org.junit.Test
class Test1 {
@Test
def test1 {
println ("Test1.test1 is here!")
}
}

./src/test/scala/Test2.scala

import org.junit.Test
import org.junit.BeforeClass
object Test2 {
var x = 0
@BeforeClass
def setUp {
x = 42
}
}
class Test2 {
@Test
def test2 {
println ("Test2.test2 is here!")
}
}

./src/test/scala/org/bla/blub/Test3.scala

package org.bla.blub
import org.junit.Test
import org.junit.BeforeClass
object Test3 {
var x = 0
@BeforeClass
def setUp {
x = 42
}
}
class Test3 {
@Test
def test3 {
println ("Test3.test3 is here!")
}
}

And here is the output sbt produces when running test

$ sbt
[info] Set current project to sbt junit test project (in build file:/Users/bnord/tests/sbttest/)
> test
[info] Updating {file:/Users/bnord/tests/sbttest/}default-e153b9...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Resolving com.novocode#junit-interface;0.8 ...
[info] Resolving junit#junit;4.8.2 ...
[info] Resolving org.scala-tools.testing#test-interface;0.5 ...
[info] Done updating.
Test3.test3 is here!
Test2.test2 is here!
Test1.test1 is here!
[info] Passed: : Total 3, Failed 0, Errors 0, Passed 3, Skipped 0
[success] Total time: 1 s, completed 22.02.2012 11:34:15
> test
Test1.test1 is here!
Test3.test3 is here!
Test2.test2 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:17
> test
Test3.test3 is here!
Test1.test1 is here!
Test2.test2 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:19
> test
Test1.test1 is here!
Test2.test2 is here!
Test3.test3 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:20
> test
Test3.test3 is here!
Test2.test2 is here!
Test1.test1 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:21
> test
Test3.test3 is here!
Test2.test2 is here!
Test1.test1 is here!
[info] Passed: : Total 1, Failed 0, Errors 0, Passed 1, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:23
> test
Test3.test3 is here!
Test1.test1 is here!
Test2.test2 is here!
[info] Passed: : Total 2, Failed 0, Errors 0, Passed 2, Skipped 0
[success] Total time: 0 s, completed 22.02.2012 11:34:27