最近、単体テストでScalaMockライブラリの使用が開始され、同じスタブ(テストスイートでグローバルに宣言されたもの)を複数のテストで使用するまでうまく動作します。ここでScalaMock:スタブは最初のテストでのみ動作します
は一例です:
import org.scalamock.scalatest.MockFactory
import org.scalatest.FunSuite
trait Bank {
def transaction(amount: Double): Double
def deposit(amount: Double): Double
}
class OloloSuite extends FunSuite with MockFactory {
val fakeBank = stub[Bank]
(fakeBank.transaction _).when(10.0).returns(9.0)
(fakeBank.deposit _).when(10.0).returns(11.0)
//Pass
test("Transaction test") {
assert(fakeBank.transaction(10.0) === 9.0)
}
//Fails
test("Deposit test") {
assert(fakeBank.deposit(10.0) === 11.0)
}
}
"入金テストは" 合格するためにどのように?