【问题标题】:Verification tests in ScalaScala 中的验证测试
【发布时间】:2011-09-18 18:38:28
【问题描述】:

我想在我的测试中做一些验证,但它永远不会失败

import org.testng.annotations.Test
import org.specs.Specification
import org.specs.mock.Mockito
import org.mockito.Matchers._

class Tests extends Specification with Mockito{
  class Foo {
    def bar(){}
  }
  @Test def simplestTest() {
    val t = mock[Foo]
    t.bar()
    there was one(t).bar()   //pass
  }
  @Test def simplestFailTest() {
    val t = mock[Foo]
    there was one(t).bar()  //pass
  }
  @Test def testFail() {
    assert(false)           //fails
  }
}

我将它作为 TestNG 测试运行。我哪里错了?

【问题讨论】:

  • 我模糊记得在模拟断言之后需要进行某种断言。尝试在there was one(t).bar() 之后添加assert(true),看看是否有任何改变。
  • @Daniel C. Sobral,不幸的是它没有改变任何东西

标签: unit-testing scala testng verification mockito


【解决方案1】:

规范似乎不支持使用 TestNG 运行测试:http://code.google.com/p/specs/wiki/RunningSpecs

【讨论】:

  • 您可以做的一件事是将您的测试编写为 TestNG 测试,并使用 specs2 特征进行更好的匹配/模拟:etorreborre.github.com/specs2/guide/…
  • @Eric,支持 TestNG 是否有任何问题或尚未完成?
猜你喜欢
  • 2022-12-11
  • 2023-03-08
  • 1970-01-01
  • 2015-07-12
  • 2012-06-29
  • 2012-03-02
  • 2020-10-23
  • 1970-01-01
  • 2022-11-13
相关资源
最近更新 更多