ScalaTest:是否可以结合使用AsyncWordSpec和GuiceOneAppPerSuite

时间:2018-09-01 10:46:15

标签: scala playframework scalatest

我想将验收测试从WordSpec切换到AsyncWordSpec

现有特征如下:

import org.scalatest.WordSpec
import org.scalatestplus.play.guice.GuiceOneAppPerSuite

class PetDBSpec
    extends WordSpec
    with GuiceOneAppPerSuite {
}

如果我更改为AsyncWordSpec,则必须这样更改:

import org.scalatest._
import org.scalatestplus.play.guice.GuiceOneAppPerSuite

class PetDBSpec
    extends AsyncWordSpec
    with GuiceOneAppPerSuite {  this: TestSuite =>
}

但仍然会出现此异常:

[error] ... class PetDBSpec needs to be abstract, since method withFixture in trait TestSuiteMixin of type (test: PetDBSpec.this.NoArgTest)org.scalatest.Outcome is not defined
[error] (Note that TestSuiteMixin.this.NoArgTest does not match AsyncTestSuite.this.NoArgAsyncTest)

它与我的UnitTests一起正常工作。

  • 我需要调整测试吗?
  • 还是无法将它们混合?

使用的版本:

  • 播放:2.6.15
  • scala测试:3.0.5
  • scalatestplus播放:3.1.2

2 个答案:

答案 0 :(得分:1)

GuiceOneAppPerSuite的声明如下:

trait GuiceOneAppPerSuite 
    extends BaseOneAppPerSuite 
    with GuiceFakeApplicationFactory { this: TestSuite =>

}

从上面的代码中,您可以看到GuiceOneAppPerSuite希望与TestSuite混合使用。

import org.scalatest._
import org.scalatestplus.play.guice.GuiceOneAppPerSuite

class PetDBSpec
    extends AsyncWordSpec
    with TestSuite
    with GuiceOneAppPerSuite { 

}

答案 1 :(得分:0)

我在Github中发现了未解决的问题:

https://github.com/playframework/scalatestplus-play/issues/112