避免在ScalaTest中继承超类测试

问题描述:

我想使用另一个项目中的测试代码,该项目已将一些实用程序方法及其测试紧密结合在一起.我想从此类继承,因此我可以使用实用程序方法,但不希望进行附带的测试.有没有一种方法可以从其他套件继承而无需注册测试?

I'd like to use test code from another project which has tightly coupled some utility methods along with their tests. I would like to inherit from this class so I'm able to use the utility methods but don't want the accompanying tests. Is there a way to inherit from this other Suite without also registering the tests?

我尝试从标有@DoNotDiscover批注的类的副本扩展,但这似乎并没有达到预期的效果.

I've tried extending from a replica of the class labeled with the @DoNotDiscover annotation but this doesn't seem to have the desired effect.

如果还有某种方式也可以忽略从父级套件继承的所有测试,我也很感兴趣.

I'd also be interested if there was some way of just ignoring all the tests inherited form the parent suite as well.

我的解决方法是制作另一个套件的实例并保存在我的测试类中.然后使用我的测试代码从另一个项目的实例化类中调用方法.

My workaround was to make an instance of the other suite and hold within my test class. Then call the methods from within the other project's instantiated class using my test code.

这需要一点点重写,因为我需要更改在其他类中创建的一些默认参数以适合我们的测试模式,但相对而言比较容易.

This required a bit of overriding since I needed to change a few default parameters made in the other class to fit our testing schema but was relatively painless.