2016-11-14 14 views
2

私はscalatestとscalamockを初めて使っています。ここで私はここにScalaMock with scalatest

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" 
) 

そして、私のSBTファイルでそれを持っているものである私は、私は次のようなエラーに取得sbt test:compileを行うだとき

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 
} 

を模擬しようとしているクラスがある

[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. 

任意の提案を取得しますか?あなたのSBTファイルにMockitoを追加

答えて

5

試してみてください。https://mvnrepository.com/artifact/org.mockito/mockito-all 1.10の場合:

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の依存関係です)、それは、単純な "%" ではなく、二重の一つだ、注意してください0.19は、あなたのコードベースと互換性がありません

EDIT:SBTコンソールでこれをあなたの第二の問題を助けるが、しようとしている

わからない:

> clean 
> compile 
+0

scalockはmockitoのトップに基づいていますか? –

+0

質問に編集を参照してください –

+0

いいえ、scalamockとmockitoは2つの異なるプロジェクトです。両方のライブラリをテストケースに含めるとは分かりませんでした。あなたのテストケースで "import org.scalatest.mockito.MockitoSugar._"行を削除し、org.mockito "%" mockito-all "%" 1.10.19 "%Test"行を削除しますbuild.sbtファイルを開き、もう一度やり直してください。そのページも参照してください:http://scalamock.org/user-guide/integration/ –

0

scalacheck 3.2 scalatest 2.1.3に依存していますが、scalatest 3.0.0を使用しています。互換性はありません。スカラシの依存を取り除くことで問題が解決されます。

1

バージョン< 3.3.0はScalatest 3+と互換性がありません。

私はscalamock 3.4.2(最新のものを書いている)に更新することをお勧めします。

最新のバージョンは、常にMaven Centralで見つけることができます。

また、自動的に引き込まれるscalamock-coreを指定する必要はありません。

関連する問題