4

我正在尝试将我的项目设置为使用 scalatest 和 scalamock。我正在使用 scala 版本 2.10.0。
但是,我似乎无法获得正确的依赖关系。

我从这段代码开始:

class  ControllerTest extends org.scalatest.FunSuite 
                      with org.scalamock.scalatest.MockFactory {}

我尝试了两种版本组合:

1)

  • org.scalatest:scalatest_2.101.9.1
  • org.scalamock:scalamock-scalatest-support_2.103.0.1

这就是我得到的:

scala: bad symbolic reference. 
A signature in MockFactory.class refers to type SuiteMixin in package org.scalatest which is not available. 
It may be completely missing from the current classpath, or the version on the classpath might be incompatible with the version used when compiling MockFactory.class.

注意:在scalamock 文档中,指定的工件 id 没有尾随 _2.10,但 maven 找不到任何这样命名的工件。另外,我在他们的网站上找不到 scalamock 应该使用的 scalatest 版本。

2)

  1. org.scalatest:scalatest_2.101.9.1
  2. org.scalamock:scalamock-scalatest-support_2.10.0-RC53.0-M8

编译器说:

scala: overriding method nestedSuites in trait SuiteMixin of type => scala.collection.immutable.IndexedSeq[org.scalatest.Suite];
method nestedSuites in trait Suite of type => List[org.scalatest.Suite] has incompatible type
class ControllerTest extends FunSuite with MockFactory {


scala: class ControllerTest needs to be abstract, since:
it has 5 unimplemented members.
/** As seen from class ControllerTest, the missing signatures are as follows.
 *  For convenience, these are usable as stub implementations.
 */
  def rerunner: Option[String] = ???
  def run(testName: Option[String],args: org.scalatest.Args): org.scalatest.Status = ???
  protected def runNestedSuites(args: org.scalatest.Args): org.scalatest.Status = ???
  protected def runTest(testName: String,args: org.scalatest.Args): org.scalatest.Status = ???
  protected def runTests(testName: Option[String],args: org.scalatest.Args): org.scalatest.Status = ??? 

那么,这个 SuiteMixin 特性是怎么回事?
如果我使用 scalatest-support_2.10.0-RC5:3.0-M8,它似乎存在于scalatest lib中。
如果我使用 scalatest-support_2.10:3.0.1,它似乎已经从所说的 scalatest 库中消失了。

这是什么魔法?而且,更重要的是,我应该使用什么版本组合来使其工作?

谢谢!

4

2 回答 2

6

如果你有这个依赖

"org.scalamock" %% "scalamock-scalatest-support" % "3.0.1" % "test"

它将自动下载正确版本的 scalatest。在这种情况下

org.scalatest#scalatest_2.10;2.0.M5b!scalatest_2.10.jar

在大多数情况下,一个库依赖于另一个库,您只需将那个库添加为依赖项。类似 Sbt 的工具将获得其他依赖项。

于 2013-02-28T18:24:12.230 回答
2

EECOLOR 的回答是正确的。详细地说,问题的原因是您选择的 ScalaMock 版本是针对更高版本的 ScalaTest (2.0.M5b) 编译的,而不是您明确尝试使用的版本 (1.9.1)。

于 2013-02-28T19:07:31.787 回答