【问题标题】:Why don't junit tests get executed with "sbt test"?为什么不使用“sbt test”执行junit测试?
【发布时间】:2016-09-29 03:20:54
【问题描述】:

我正在使用带有纯 java 项目的 sbt 版本 0.13.2。

我的build.sbt 中有以下行:

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

我的测试是这样的:

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);
    }
}

当我从命令行执行sbt test 时,测试编译成功,但测试没有运行。它说

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

知道如何执行测试吗?

【问题讨论】:

  • 面临与您相同的问题,junit-interface 似乎无法正确处理 RunWith 属性。就我而言,我需要 RunWith 来通过 Junit 参数驱动我的测试。我能找到的只是github.com/sbt/junit-interface/issues/66,希望它尽快得到修复......
  • 我什至不知道“junit-interface”。将它添加到我的 sbt 依赖项使 sbt test 能够运行我的 Java 单元测试!谢谢
  • 有关如何将 JUnit 支持添加到 SBT stackoverflow.com/questions/28174243/run-junit-tests-with-sbt 的相关问题

标签: junit sbt


【解决方案1】:

当我删除 @RunWith 注释时,我的测试运行得很好。我不知道为什么这解决了问题。

【讨论】:

  • 会不会是the check的原因?
  • 顺便说一句,如果它对你有用,你能批准你的答案吗?谢谢!
【解决方案2】:

要尝试的另一件事是从命令行而不是交互式运行测试。出于某种原因,我发现这对我有用。

>sbt ProjectName/test 

而不是交互:

>sbt
>project ProjectName
>test

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-26
    • 1970-01-01
    • 2012-06-07
    • 1970-01-01
    • 2016-05-30
    • 2017-12-23
    • 2019-11-04
    相关资源
    最近更新 更多