我正在使用scala 2.12。这是我的build.sbt文件
libraryDependencies ++= Seq(
"net.codingwell" %% "scala-guice" % "4.1.0",
"org.scalatest" %% "scalatest" % "3.0.3" % "test",
"org.scalamock" %% "scalamock-scalatest-support" % "3.5.0" % "test"
)
我正在尝试为Guice编写一个测试模块,它也使用Mocking
我试过
class TestModule extends ScalaModule with MockitoSugar{
val x = mock[TestPartialMock]
override def configure(): Unit = {
bind[Test1]
bind[Test2]
}
}
我收到了错误
Error:scalac: Error: requirement failed: package stubbing
java.lang.IllegalArgumentException: requirement failed: package stubbing
at scala.reflect.internal.Types$ModuleTypeRef.<init>(Types.scala:1879)
at scala.reflect.internal.Types$PackageTypeRef.<init>(Types.scala:1897)
at scala.reflect.internal.Types$TypeRef$.apply(Types.scala:2401)
at scala.reflect.internal.Types.typeRef(Types.scala:3553)
at scala.reflect.internal.Types.typeRef$(Types.scala:3536)
at scala.reflect.internal.SymbolTable.typeRef(SymbolTable.scala:16)
at s
我也试过
class TestModule extends AbstractModule with ScalaModule with MockitoSugar {
override def configure() = {
}
}
但现在我收到错误
Error:(14, 17) Symbol 'type <none>.stubbing.Answer' is missing from the classpath.
This symbol is required by 'value org.scalatest.mockito.MockitoSugar.defaultAnswer'.
Make sure that type Answer is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of <none>.stubbing.
override def configure() = {
然后我试了
class TestModule extends AbstractModule with ScalaModule with MockFactory with MockitoSugar {
override def configure() = {
}
}
但是我收到了这个错误
Error:(14, 17) Symbol 'type <none>.mockito.MockSettings' is missing from the classpath.
This symbol is required by 'value org.scalatest.mockito.MockitoSugar.mockSettings'.
Make sure that type MockSettings is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of <none>.mockito.
override def configure() = {
在我看来,不可能在同一类中使用Guice AbstractFactory和MockitoSugar。
答案 0 :(得分:5)
我尝试了一点,我解决了。留下答案,以便其他人可以找到它。
这有效
SBT
"net.codingwell" %% "scala-guice" % "4.1.0",
"org.scalatest" % "scalatest_2.12" % "3.0.3",
"org.mockito" % "mockito-core" % "2.7.22"
现在将类定义为
class TestModule extends AbstractModule with ScalaModule with MockitoSugar {
override def configure() = {}
}