考虑以下org.scalatest.TagAnnotation
子类:
public class TestSizeTags {
/** Tests with crazy long runtimes **/
@org.scalatest.TagAnnotation
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public static @interface HugeTestClass {}
}
让我们annotate
/ tag
一个类吧:
@HugeTestClass
class ItemsJobTest extends FunSuite with BeforeAndAfterEach with DataFrameSuiteBase {
现在我们想在代码库上快速“冒烟测试套件”;因此,让我们(尝试)排除由HugeTestClass
注释的测试用例:
命令行:
sbt test * -- -l HugeTestClass
或者也许:
sbt 'testOnly * -- -l HugeTestClass'
让我们也在sbt本身内尝试:
sbt> testOnly * -- -l HugeTestClass
在所有案例中,我们(不幸的是)仍然看到:
[info] ItemsJobTest:
^C[info] - Run Items Pipeline *** FAILED *** (2 seconds, 796 milliseconds)
所以测试实际确实运行..与意图相反。
那么通过Tag Filter(/Exclusion)
向sbt
类应用scalatest
的正确语法/方法是什么?
答案 0 :(得分:2)
你错过了将testOnly
部分放在双引号中,并且还给了标签注释的完整包以忽略,
sbt "test-only * -- -l full.package.to.HugeTestClass"
例如,
标记注释
package tags;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@org.scalatest.TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface ExcludeMePleaseTag {}
测试排除
@tags.ExcludeMePleaseTag
class ExcludeMeSpecs extends FlatSpec with Matchers {
"I" should " not run" in {
888 shouldBe 1
}
}
排除测试
sbt "test-only * -- -l tags.ExcludeMePleaseTag"
这个github问题很有帮助 - https://github.com/harrah/xsbt/issues/357#issuecomment-44867814
但它不适用于静态标记注释
public class WrapperClass {
@org.scalatest.TagAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public static @interface ExcludeMePleaseTag {
}
}
sbt "test-only * -- -l tags.WrapperClass.ExcludeMePleaseTag"