简体   繁体   English

根据规范运行单个测试

[英]Running an individual test from a specification

Is there a way to run a specific test from a Specs 2 Specification ? 有没有一种方法可以运行来自Specs 2 Specification的特定测试? eg If I have the following: 例如,如果我有以下内容:

class FooSpec extends Specification {
  "foo" should {
    "bar" in {
      // ...
    }

    "baz" in {
      // ...
    }
  }
}

I would like to have a way to run only FooSpec > "foo" > "bar" (using some arbitrary notation here). 我想有一种方法只运行FooSpec > "foo" > "bar" (在这里使用一些任意符号)。

You can use the ex argument from sbt to run a specific example: 您可以使用sbt中的ex参数来运行特定示例:

sbt> test-only *FooSpec* -- ex bar

You can also mix-in the org.specs2.mutable.Tags trait and include a specific tag: 您还可以混入org.specs2.mutable.Tags特性,并包括一个特定的标签:

sbt> test-only *FooSpec* -- include investigate

class FooSpec extends Specification with Tags {
  "foo" should {
    tag("investigate")
    "bar" in {
      // ...
    }
    "baz" in {
       // ...
     }
   }
}

You can also just re-run the previously failed examples, whatever they are 您也可以重新运行先前失败的示例,无论它们是什么

sbt> test-only *FooSpec* -- was x

Finally, in the next 2.0 release (or using the latest 1.15-SNAPSHOT), you will be able to create a script.Specification and use "auto-numbered example groups": 最后,在下一个2.0版本(或使用最新的1.15-SNAPSHOT)中,您将能够创建script.Specification并使用“自动编号的示例组”:

import specification._

/**
 * This kind of specification has a strict separation between the text 
 * and the example code
 */ 
class FooSpec extends script.Specification with Groups { def is = s2"""
  This is a specification for FOO

  First of all, it must do foo
  + with bar
  + with baz

  """ 

  "foo" - new group {
    eg := "bar" must beOk
    eg := "baz" must beOk
  }
}

// execute all the examples in the first group
sbt> test-only *FooSpec* -- include g1

// execute the first example in the first group
sbt> test-only *FooSpec* -- include g1.e1

There is however no way to specify, with a mutable Specification, that you want to run the example "foo" / "bar" . 但是,无法使用可变的Specification来指定要运行示例"foo" / "bar" This might be a feature to add in the future. 这可能是将来添加的功能。

You can choose the namespace of tests to be executed, but AFAIK there's no way to run a specific test from the sbt console . 您可以选择要执行的测试的名称空间,但是AFAIK无法从sbt console运行特定的测试。 You can do something like: 您可以执行以下操作:

sbt test:compile "test-only FooSpec.*" , which runs the tests only from the FooSpec namespace, but this selection is namespace based and not even that works properly. sbt test:compile "test-only FooSpec.*" ,它仅从FooSpec命名空间运行测试,但是此选择基于命名空间,甚至不能正常工作。 This is the selection mechanism, but it somehow fails and always runs the entire set of tests found in your project. 这是选择机制,但是它某种程度上失败了,并且总是运行在项目中找到的整套测试。

Update 更新

From the official documentation : 官方文档中

test-only

The test-only task accepts a whitespace separated list of test names to run. 仅测试任务接受由空格分隔的测试名称列表以运行。 For example: 例如:

test-only org.example.MyTest1 org.example.MyTest2

It supports wildcards as well: 它也支持通配符:

test-only org.example.*Slow org.example.MyTest1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从命令行为 iOS 应用程序运行单个 XCTest(UI、单元)测试用例 - Running individual XCTest (UI, Unit) test cases for iOS apps from the command line 从CCNet中选择并运行各个测试用例 - Select and run individual test cases from CCNet 在 Xcode 中运行单个测试用例时,`执行了 0 次测试,0 次失败(0 次意外)` - `Executed 0 tests, with 0 failures (0 unexpected)` when running individual test cases in Xcode 带有服务的Grails规格测试 - Grails specification test with service 如何从其相应的测试资源执行单个 JUnit 测试 - How to execute an individual JUnit test from its corresponding test resources 当运行单个测试与整体运行pytest时,os.getcwd()的python unittest值会更改 - python unittest value of os.getcwd() changes when running individual test vs running pytest as whole 从命令行运行 Actionscript 测试 - Running Actionscript Test from CommandLine 如何编写弹簧规格的单元测试? - How to write a unit test for spring specification? 在spock单元测试规范中传递实际参数 - Passing actual parameters in a spock unit test specification 使用spock lang规范测试控制器的选项 - Option of using spock lang specification test a Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM