2016-11-14 7 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 
) 

것은주의, 그것은 단순한 "%",하지

다른 버전 여기에 이중 하나 (은 자바 의존성의)입니다 0.19이 당신의 코드베이스와 호환되지 않습니다

편집 : SBT 콘솔에서 그 두 번째 문제를 도움이되지만 시도 할 것이다

확실하지 :

> clean 
> compile 
+0

mockito의 맨 위에 scalamock이 있습니까? –

+0

질문에서 편집을 참조하십시오 –

+0

아니요, scalamock과 mockito는 서로 다른 두 가지 프로젝트입니다. 테스트 케이스에 두 라이브러리를 모두 포함 시켰는지 이해하지 못했습니다. 나는 당신의 테스트 케이스에서 "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을 사용하므로 호환성이 없습니다. Scatest 의존성을 제거하면 문제가 해결됩니다.

1

버전 < 3.3.0은 Scalatest 3+와 호환되지 않습니다.

저는 scalamock 3.4.2로 업데이트하는 것이 좋습니다.

언제든지 최신 버전을 Maven Central에서 찾을 수 있습니다.

또한 scalamock-core를 지정할 필요가 없으므로 자동으로 가져옵니다.