2013-05-08 97 views
2

有没有办法从规格2 Specification运行特定测试?例如如果我有以下几点:从规范中运行单独测试

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

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

我想有一种方式来运行只有FooSpec > "foo" > "bar"(这里使用了一些任意的符号)。

回答

5

可以使用ex参数从SBT运行一个具体的例子:

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

您也可以混合在org.specs2.mutable.Tags特征并包括特定标签:

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

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

你也可以只是重新运行先前失败的例子,不管他们是

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

最后,在未来的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 

但是没有办法来指定,具有可变的规范,要运行示例"foo"/"bar"。这可能是未来添加的功能。

+0

在scala IDE中如何做? – zinking 2014-05-01 01:52:43

1

您可以选择要执行的测试命名空间,但AFAIK无法运行sbt console中的特定测试。你可以这样做:

sbt test:compile "test-only FooSpec.*",它只从FooSpec命名空间运行测试,但是这个选择是基于命名空间的,甚至不能正常工作。这是选择机制,但它以某种方式失败并始终运行在您的项目中找到的整套测试。

更新

official documentation

test-only

唯一的测试任务接受测试名称的空格分隔的列表来运行。例如:

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

它支持通配符还有:

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

这使我可以达到'FooSpec'的水平,但不会更深。 – missingfaktor 2013-05-08 11:54:15