加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

ScalaTest没有运行任何测试

发布时间:2020-12-16 18:52:48 所属栏目:安全 来源:网络整理
导读:我正在尝试运行我的测试: 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",scalaVersio
我正在尝试运行我的测试:
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()
            } 
        }
    }

它总是显示:

[info]没有执行任何测试.

任何艰难的方式都没有用?

解决方法

目录结构不是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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读