“运行scala测试”;规格“;以编程方式归档

“运行scala测试”;规格“;以编程方式归档,scala,unit-testing,integration-testing,Scala,Unit Testing,Integration Testing,我有一个Spec子类B,它扩展了另一个Speca,我希望每当我运行a测试文件时,B中的测试也能运行。 (A和B在同一个文件中) 有没有一种方法可以通过在类a中添加一些scala代码以编程方式实现这一点。 就像在A中一样,我是否可以以某种方式实例化Spec类,然后在该对象上调用runTests class SpecB extends Specification { new SpecA() // it is a fragment and will be executed within the

我有一个
Spec
子类B,它扩展了另一个
Spec
a,我希望每当我运行a测试文件时,B中的测试也能运行。 (A和B在同一个文件中)

有没有一种方法可以通过在类a中添加一些scala代码以编程方式实现这一点。 就像在A中一样,我是否可以以某种方式实例化
Spec
类,然后在该对象上调用
runTests

class SpecB extends Specification {
    new SpecA() // it is a fragment and will be executed within the other
    // more logic here
}


// if you're NOT in a Spec, this might be helpful:

implicit val app: Application = play.api.test.Helpers.baseApplicationBuilder.build
Play.start(app)
org.specs2.runner.TextRunner.run(
  new org.specs2.mutable.Specification {
       1 === 1
       // and app.injector stuff e.g. 
  }
}.flush

我想,用一些代码和更多细节来重新问这个问题。如果B扩展了A,A不应该知道B,那就没有意义了。也可以将B合并到A中。不要扩展规范类。例如,这在单元测试参数化上下文中工作