18
votes

I am using sbt version 0.13.2 with a pure java project.

My build.sbt has the following line in it:

libraryDependencies ++= Seq("com.novocode" % "junit-interface" % "0.10" % "test")

My test looks like this:

import org.junit.Test;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.Assert.*;

@RunWith(JUnit4.class)
public class ExampleTest{
    @Test
    public void firstTest(){
        org.junit.Assert.assertEquals("2.5 + 7.5 = 10.0", 2.5 + 7.5, 10.0, .1);
    }
}

When I do sbt test from the command line, the test is successfully compiled, but the test does not run. It says

Compiling 1 Java source to [my path]/target/scala-2.10/test-classes...
...
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0 
[success] Total time: 1 s, completed May 31, 2014 5:56:22 PM

Any idea how to get the test executed?

2
Facing same issue as you, junit-interface does not seem to properly handle the RunWith attribute. In my case I needed the RunWith to data drive my tests via Junit parameters. All I was able to find was github.com/sbt/junit-interface/issues/66 let's hope it gets fixed soon... - donhector
I didn't even know about "junit-interface". Adding it to my sbt dependencies enabled sbt test to run my Java unit tests! Thanks - devdanke
Related question about how to add JUnit support to SBT stackoverflow.com/questions/28174243/run-junit-tests-with-sbt - Peter Lamberg

2 Answers

0
votes

When I remove the @RunWith annotation, my tests run just fine. I don't know why this resolved the problem.

0
votes

Another thing to try is to run the tests from the command line and not interactive. For some reason I found that to work for me.

>sbt ProjectName/test 

instead of interactively:

>sbt
>project ProjectName
>test