如何在ScalaTest中禁用测试套件

lam*_*das 21 testing scala scalatest

如何禁用测试套件,即类扩展中的所有测试FunSpec

我已经发现的唯一的解决办法是更换itignore每次试验前,但它是无聊与几十个测试这样做.

Bil*_*ers 32

在1.8中执行此操作的简单方法是添加一个带有伪参数的构造函数.如果没有public,no-arg构造函数,ScalaTest(和sbt)将不会发现该类:

class MySuite(ignore: String) extends FunSuite { 
  // ...
}
Run Code Online (Sandbox Code Playgroud)

在2.0中,您将能够在课堂上编写@Ignore:

@Ignore
class MySuite extends FunSuite {
  // ...
}
Run Code Online (Sandbox Code Playgroud)

  • 我尝试了此操作,但没有影响,我正在使用scala 2.10.2,请帮帮我。@BillVenners (2认同)

Scr*_*tch 7

根据scalatest文档,假设您是否有这样的测试套件

describe ("some component") {
  it ("should do something") {
   ...
  }
  it ("should also do something else") {
   ...
  }
}
Run Code Online (Sandbox Code Playgroud)

要仅禁用单个测试,您可以使用该ignore()方法。

describe ("some  component") {
  ignore ("should do something") {
   ...
  }
  ...
}
Run Code Online (Sandbox Code Playgroud)


Mit*_*tin 5

您可以将@Ignore用于不同的测试和整个套装.


Jam*_*ore 5

使用@DoNotDiscover

来自scaladoc

import org.scalatest._

@DoNotDiscover
class SetSpec extends FlatSpec {

  "An empty Set" should "have size 0" in {
    assert(Set.empty.size === 0)
  }

  it should "produce NoSuchElementException when head is invoked" in {
    intercept[NoSuchElementException] {
      Set.empty.head
    }
  }
}
Run Code Online (Sandbox Code Playgroud)