ScalaMock со скалатестом

Я новичок в 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.

Какие-либо предложения?


person Abdul Rahman    schedule 14.11.2016    source источник


Ответы (3)


Попробуйте добавить 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 несовместима с вашей кодовой базой

РЕДАКТИРОВАТЬ :

Не уверен, что это поможет вашей второй проблеме, но попробуйте это в консоли SBT:

> clean
> compile
person Patrick Laxton    schedule 14.11.2016
comment
Скаламак основан на мокито? - person Abdul Rahman; 15.11.2016
comment
Нет, scalamock и mockito — это два разных проекта. Я не понял, что вы включили обе библиотеки в свой тестовый пример. Я бы сказал, удалите строку import org.scalest.mockito.MockitoSugar._ в вашем тестовом примере и тестовую строку org.mockito % mockito-all % 1.10.19 % в вашем файле build.sbt, а затем повторите попытку. См. также эту страницу: scalamock.org/user-guide/integration - person Patrick Laxton; 18.11.2016

Версии ‹3.3.0 несовместимы со Scalatest 3+.

Я предлагаю обновить до scalamock 3.4.2 (последняя на момент написания).

Вы всегда можете найти самую новую версию на Maven Central.

Кроме того, не нужно указывать scalamock-core, он подтягивается автоматически.

person Philipp    schedule 17.01.2017

scalacheck 3.2 зависит от scalatest 2.1.3, но вы использовали scalatest 3.0.0, поэтому они несовместимы. удаление зависимости scalest решит проблему.

person 李学斌    schedule 22.12.2016