sbt 上的 ScalaTest 没有运行任何测试

标签 scala sbt scalatest

我正在尝试运行我的测试:
sbt 然后测试。

我的 build.sbt 看起来像这样

lazy val scalatest =  "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
lazy val root = (project in file(".")).
settings(
    name := "highlight2pdf",
    version := "0.1",
    scalaVersion := "2.11.6",
    libraryDependencies +=  scalatest
)

我只是将示例测试放在 test/scala 上
    import collection.mutable.Stack
    import org.scalatest._

    class ExampleSpec extends FlatSpec with Matchers {

        "A Stack" should "pop values in last-in-first-out order" in {
            val stack = new Stack[Int]
            stack.push(1)
            stack.push(2)
            stack.pop() should be (2)
            stack.pop() should be (1)
        }

        it should "throw NoSuchElementException if an empty stack is popped" in {
            val emptyStack = new Stack[Int]
            a [NoSuchElementException] should be thrownBy {
                emptyStack.pop()
            } 
        }
    }

仍然总是显示:

[信息] 未执行任何测试。

关于为什么它不起作用的任何想法?

最佳答案

目录结构不是 sbt 的正确约定找 ExampleSpec.scala默认情况下。

├── built.sbt
├── src
│   └── test
│       └── scala
│           ├── ExampleSpec.scala

将其更改为上面的结构并运行 sbt test在顶级目录中,它应该可以工作。同样,scala 源将进入 src/main/scala并且会被编译。
> test
[info] Compiling 1 Scala source to /tmp/TestsWontRun/target/scala-2.11/test-classes...
[info] ExampleSpec:
[info] A Stack
[info] - should pop values in last-in-first-out order
[info] - should throw NoSuchElementException if an empty stack is popped
[info] Run completed in 289 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 7 s, completed Apr 30, 2015 8:54:30 AM

关于sbt 上的 ScalaTest 没有运行任何测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29972284/

相关文章:

scala - 如何使用 IntelliJ IDEA 生成 Scala setter 和 getter

scala - Scala 中 f(a,b) 和 f(a)(b) 之间的区别

scala - 我无法使用流模式在 apache Spark 中使用 scala 进行在线预测来制作数据帧

java - SBT构建,在编译和运行时从子项目运行主类

scala - java.lang.IncompatibleClassChangeError:使用ScalaCheck和ScalaTest实现类

scala - scala中的动态代码评估

scala - Spark ClassNotFoundException 运行 master

java - 使用 SBT 将 Artifact 发布到本地 Maven 仓库并在 ​​Gradle 项目中使用它

scala - 如何将非托管 jar 添加到 g8 模板生成的 build.sbt?

scala - 何时在具有 BeforeAndAfter 特性的 ScalaTest 类中调用 before() 和 after()