2

私はscalatestとscalamockが初めてです。これが私のsbtファイルにあるものです

name := "cakepattern"
version := "0.1"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % "3.0.0" % "test",
  "org.scalamock" %% "scalamock-core" % "3.1.1" % "test",
  "org.scalamock" %% "scalamock-scalatest-support" % "3.1.1" % "test",
  "org.scalacheck" %% "scalacheck" % "1.13.0" % "test"
)

そして、ここに私がモックしようとしているクラスがあります

package config

import dto.User
import services.AuthServiceComponent
import org.scalatest.mockito.MockitoSugar._
import services.impl.DefaultUserAuthServiceComponent


trait MockAuthServiceComponent extends AuthServiceComponent{

  val x = mock[AuthServiceLike]

  type AuthService = x.type
  override val userAuthService = x
}

私がやるsbt test:compileと、次のエラーが表示されます

[error] missing or invalid dependency detected while loading class file 'MockitoSugar.class'.
[error] Could not access term mockito in package org,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of org.
[error] missing or invalid dependency detected while loading class file 'MockitoSugar.class'.
[error] Could not access type MockSettings in value org.mockito,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of org.mockito.
[error] missing or invalid dependency detected while loading class file 'MockitoSugar.class'.
[error] Could not access type Answer in value org.stubbing,
[error] because it (or its dependencies) are missing. Check your build definition for
[error] missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
[error] A full rebuild may help if 'MockitoSugar.class' was compiled against an incompatible version of org.stubbing.
[error] three errors found
[error] (test:compileIncremental) Compilation failed

私は何が欠けていますか?

[編集]

以前抱えていた問題は解決しましたが、今はこれが得られます

Error:scalac: missing or invalid dependency detected while loading class file 'AbstractMockFactory.class'.
Could not access type NoArgTest in trait org.scalatest.Suite,
because it (or its dependencies) are missing. Check your build definition for
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
A full rebuild may help if 'AbstractMockFactory.class' was compiled against an incompatible version of org.scalatest.Suite.

助言がありますか?

4

3 に答える 3

5

Mockito を sbt ファイルに追加してみてください:

libraryDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % "3.0.0" % Test,
  "org.scalamock" %% "scalamock-core" % "3.1.1" % Test,
  "org.scalamock" %% "scalamock-scalatest-support" % "3.1.1" % Test,
  "org.scalacheck" %% "scalacheck" % "1.13.0" % Test,
  "org.mockito" % "mockito-all" % "1.10.19" % Test
)

注意してください、これは単純な「%」であり、二重ではありません (これは Java の依存関係です)。

他のバージョンはこちら: https://mvnrepository.com/artifact/org.mockito/mockito-all 1.10.19 がコードベースと互換性がない場合

編集 :

2番目の問題に役立つかどうかはわかりませんが、SBTコンソールで試してください:

> clean
> compile
于 2016-11-14T20:56:30.853 に答える
0

scalacheck 3.2 は scalatest 2.1.3 に依存していますが、scalatest 3.0.0 を使用しているため、互換性がありません。scalatest の依存関係を削除すると、問題が解決します。

于 2016-12-22T08:00:41.497 に答える