首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >scalac:错误:需求失败:包固执

scalac:错误:需求失败:包固执
EN

Stack Overflow用户
提问于 2017-04-29 13:44:31
回答 1查看 2.1K关注 0票数 2

我正在使用Scala2.12。这是我的build.sbt文件

代码语言:javascript
复制
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编写一个测试模块,它也使用了模拟

我试过

代码语言:javascript
复制
class TestModule extends ScalaModule with MockitoSugar{
   val x = mock[TestPartialMock]
   override def configure(): Unit = {
      bind[Test1]
      bind[Test2]
   }
}

我得到了错误

代码语言:javascript
复制
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

我也试过

代码语言:javascript
复制
class TestModule extends AbstractModule with ScalaModule with MockitoSugar {
   override def configure() = {
   }
}

但现在我错了

代码语言:javascript
复制
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() = {

然后我试着

代码语言:javascript
复制
class TestModule extends AbstractModule with ScalaModule with MockFactory with MockitoSugar {
   override def configure() = {
   }
}

但我知道这个错误

代码语言:javascript
复制
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是不可能的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-29 15:24:23

我再试一试就解决了。把答案留在这里好让其他人找到答案。

这行得通

SBT

代码语言:javascript
复制
"net.codingwell" %% "scala-guice" % "4.1.0",
"org.scalatest" % "scalatest_2.12" % "3.0.3",
"org.mockito" % "mockito-core" % "2.7.22"

现在将类定义为

代码语言:javascript
复制
class TestModule extends AbstractModule with ScalaModule with MockitoSugar {
   override def configure() = {}
}
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43696394

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档