Unit testing 执行封装在函数中的specs2示例
如何在包装函数中执行spec2规范的所有测试 例: 因此,这3个测试中的每一个都应该在 与(someSession){Unit testing 执行封装在函数中的specs2示例,unit-testing,scala,specs2,Unit Testing,Scala,Specs2,如何在包装函数中执行spec2规范的所有测试 例: 因此,这3个测试中的每一个都应该在 与(someSession){ 在使用ScalaTest时,我可以使用fixture进行覆盖,您可以使用以下内容: 类HelloWorldSpec使用AroundExample扩展规范{ def在[T]附近=在什么方向上(T) ... } 或: 类HelloWorldSpec扩展了规范{ 隐式对象sessionContext=newaround{ def在[T]附近=在什么方向上(T) } ... } 具
在使用ScalaTest时,我可以使用fixture进行覆盖,您可以使用以下内容:
类HelloWorldSpec使用AroundExample扩展规范{
def在[T]附近=在什么方向上(T)
...
}
或:
类HelloWorldSpec扩展了规范{
隐式对象sessionContext=newaround{
def在[T]附近=在什么方向上(T)
}
...
}
具体取决于您需要执行的操作,可能更适合使用之前
、之后之前
、或外部
上下文(以及它们的示例
对应项)的某些组合
class HelloWorldSpec extends Specification {
wrapAll(example) = {
// wrap it in a session, for example.
with(someSession){
example()
}
}
"The 'Hello world' string" should {
"contain 11 characters" in {
"Hello world" must have size(11)
}
"start with 'Hello'" in {
"Hello world" must startWith("Hello")
}
"end with 'world'" in {
"Hello world" must endWith("world")
}
}
}
class HelloWorldSpec extends Specification with AroundExample {
def around[T <% Result](t: =>T) = inWhateverSession(t)
...
}
class HelloWorldSpec extends Specification {
implicit object sessionContext = new Around {
def around[T <% Result](t: =>T) = inWhateverSession(t)
}
...
}