我对 ms Scala 测试进行了以下设置,其中我有一个如下所示的特征:
trait CPODBTestContainerSpec extends AnyFlatSpecLike with TestContainerForAll {
....
....
}
abstract class BaseCPOControllerSpec extends PlaySpec with Results with FakeApplicationFactory with CPODBTestContainerSpec {
....
....
}
当我尝试运行它时,收到以下错误消息。我清楚地理解它的意思,但我不确定如何解决这个问题。上面这两个特征做了不同的事情,我在我的范围内需要它们。
class BaseCPOControllerSpec inherits conflicting members:
protected def info: org.scalatest.Informer (defined in trait AnyWordSpecLike) and
protected def info: org.scalatest.Informer (defined in trait AnyFlatSpecLike)
(note: this can be resolved by declaring an `override` in class BaseCPOControllerSpec.);
other members with override errors are: note, alert, markup, registerTest, registerIgnoredTest, it, they, behave, styleName
abstract class BaseCPOControllerSpec extends PlaySpec with Results with FakeApplicationFactory with CPODBTestContainerSpec {
我了解了特质线性化,但不确定是否可以通过重组我的特质来解决这个问题?
冲突来自于你想要使用的特征层次结构是混合的事实:
AnyFlatSpecLike
来自您自己的CPODBTestContainerSpec
AnyWordSpecLike
来自 PlaySpec
这是使用 Scalatest 编写测试的两种不同方式。想要同时使用两者是没有意义的。
如果您需要
PlaySpec
,我会将CPODBTestContainerSpec
更改为扩展AnyWordSpecLike
。