我正在尝试使用Akka的specs2 TestKit来构建一个测试。我被一个持续的编译错误困住了,我想不出该如何解决,我希望得到一些建议。
编译错误是:
TaskSpec.scala:40: parents of traits may not have parameters
[error] with akka.testkit.TestKit( ActorSystem( "testsystem", ConfigFactory.parseString( TaskSpec.config ) ) )根据阿克卡博士和internet [医]胫以及Action的建议,我试图将TestKit合并到specs2范围中。下面是我得到错误的代码片段:
class TaskSpec
extends Specification
with AsyncTest
with NoTimeConversions {
sequential
trait scope
extends Scope
with TestKit( ActorSystem( "testsystem", ConfigFactory.parseString( TaskSpec.config ) ) )
with AkkaTestSupport {
...我有以下帮手:
trait AkkaTestSupport extends After { outer: TestKit =>
override protected def after: Unit = {
system.shutdown()
super.after
}
}发布于 2013-11-12 00:38:54
以下是你能做的一件事:
import org.specs2.mutable.SpecificationLike
import org.specs2.specification._
class TestSpec extends Actors { isolated
"test1" >> ok
"test2" >> ok
}
abstract class Actors extends
TestKit(ActorSystem("testsystem", ConfigFactory.parseString(TaskSpec.config)))
with SpecificationLike with AfterExample {
override def map(fs: =>Fragments) = super.map(fs) ^ step(system.shutdown, global = true)
def after = system.shutdown
}这应该避免编译错误,因为TestKit是一个抽象类,它只是混合特性:SpecificationLike是一个特性(Specification不是),AfterExample是一个特性。
另外,上面的规范在isolated模式下运行,这意味着为每个示例实例化了一个全新的TestSpec对象,并且AfterExample特性确保在每个示例之后系统被关闭。
最后,map方法被一个特殊的step覆盖,以确保为第一个TestSpec实例(声明所有示例的实例)创建的system将被干净地处理掉。
https://stackoverflow.com/questions/19916410
复制相似问题