sbt test仅带有标签的排除列表不起作用

问题描述 投票:3回答:1

我有一个测试班,为

import org.scalatest.FlatSpec

import scala.collection.mutable

class Tags101Spec extends FlatSpec {
  "A Stack" should "pop values in last-in-first-out order" in {
    val stack = new mutable.Stack[Int]
    stack.push(1)
    stack.push(2)
    assert(stack.pop() === 2)
    assert(stack.pop() === 1)
  }

  it should "throw NoSuchElementException if an empty stack is popped" in {
    val emptyStack = new mutable.Stack[String]
    intercept[NoSuchElementException] {
      emptyStack.pop()
    }
  }

  "A String" should "return 0 size when empty" taggedAs (Fast) in {
    assert("".size === 0)
  }

  "A Sorted List of 10 numbers" must "return 10 as the first element when reversed" taggedAs (Slow) in {
    assert(10 === (1 to 10).toList.reverse.head)
  }

}

在同一目录中,有一个名为Tags的类,它看起来像

import org.scalatest.Tag

object Slow extends Tag("Slow Tests")
object Fast extends Tag("Fast Tests")

我通过使用sbt标志包含标签来使用-n运行测试,并且有效

sbt:Unit Testing in Scala> testOnly -- -n Fast
[info] Tags101Spec:
[info] A Stack
[info] A String
[info] A Sorted List of 10 numbers
[info] Run completed in 137 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0

由于只有1测试是taggedAs(Fast),所以该测试仅运行了一个测试。

[现在,我想做相反的事情,排除Fast标记并运行其余测试。这是我尝试过的

sbt:Unit Testing in Scala> testOnly -- -l Fast
[info] Tags101Spec:
[info] A Stack
[info] - should pop values in last-in-first-out order
[info] - should throw NoSuchElementException if an empty stack is popped
[info] A String
[info] - should return 0 size when empty
[info] A Sorted List of 10 numbers
[info] - must return 10 as the first element when reversed
[info] Run completed in 252 milliseconds.
[info] Total number of tests run: 4
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 4, failed 0, canceled 0, ignored 0, pending 0

并且您看到它运行了4测试,这是所有测试,包括1 Fast标记的测试。

我在这里想念什么?如何使排除标签与sbt一起使用?

谢谢

scala sbt
1个回答
0
投票

-l-n的参数应该是传递给name的构造函数的Tag字符串参数,而不是对象的名称。例如,给定

© www.soinside.com 2019 - 2024. All rights reserved.