0
@RunWith(classOf[MockitoJUnitRunner])
class ScalaTest {

  var x  = mock[java.util.Map]
  val y  = mock[ClassA]
  val z  = mock[ClassB]
}

pom ファイルに設定した依存関係に関係なく、モックを機能させることができません。コンパイラは、シンボルMockClassOf. 以下に依存関係を示しました。

<dependency>
  <groupId>org.scalamock</groupId>
  <artifactId>scalamock-scalatest-support_${scala.version}</artifactId>
  <version>2.4</version>
</dependency>
<dependency>
  <groupId>org.scalamock</groupId>
  <artifactId>scalamock-junit3-support_${scala.version}</artifactId>
  <version>2.4</version>
</dependency>

テストの依存関係は次のとおりです。

<dependency>
  <groupId>org.scalatest</groupId>
  <artifactId>scalatest_${scala.version}</artifactId>
  <version>2.0.M3</version>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.mockito</groupId>
  <artifactId>mockito-core</artifactId>
  <version>1.9.0</version>
  <scope>test</scope>
</dependency>

これらは私の輸入品です:

import org.junit.{Test, Before}
import org.junit.runner.RunWith
import org.mockito.runners.MockitoJUnitRunner

助言がありますか??

4

2 に答える 2

3

私はモッキートを知りませんが、

クラスScalaTestはユニットスイートを拡張し、MockitoSugar(mockメソッドを提供します)をミックスインする必要があります。

classOfアノテーション宣言で解決できない場合はRunWith、おそらく新しいバージョンのScala(2.8以降)を使用する必要があります。

于 2012-08-13T12:41:12.777 に答える
0

ScalaTestとJUnitのScalaMockサポートクラスをインポートしていますが、ScalaTestをまったく使用しておらず(私がよく知らないカスタムランナーでJUnitを使用しています)、間違ったセットを使用しているようです。ヨルの質問に対するステファンのコメントによると、特性。

テストランナーとしてScalaTestを使用する場合は、関連するSuiteクラスの1つをMockitoSugarと混合する必要があります(ScalaTestのドキュメントに従ってください)。

// First, create the mock object
val mockCollaborator = mock[Collaborator]

// Create the class under test and pass the mock to it
classUnderTest = new ClassUnderTest
classUnderTest.addListener(mock)

// Use the class under test
classUnderTest.addDocument("Document", new Array[Byte](0))
classUnderTest.addDocument("Document", new Array[Byte](0))
classUnderTest.addDocument("Document", new Array[Byte](0))
classUnderTest.addDocument("Document", new Array[Byte](0))

// Then verify the class under test used the mock object as expected
verify(mockCollaborator).documentAdded("Document")
verify(mockCollaborator, times(3)).documentChanged("Document")
于 2012-10-24T13:49:28.493 に答える