Why don't junit tests get executed with “sbt t

2019-04-18 16:33发布

问题:

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?

回答1:

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



回答2:

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


标签: junit sbt