2013-01-11 39 views
5

Çok basit bir test yapıyorum ve bir özellik ile uğraşmaya çalışıyorum. Test bile çalışmaz ve başlatma hatası ile başarısız olur: java.lang.IllegalArgumentException: gereksinim başarısız oldu: withExpectations kullanmayı hatırladınız mı? İşteScalaMock proxy cihazlarını nasıl kullanırım?

benim çok basit bir testtir:

Eğer resetMocks çağırmanız gerekir
import org.scalatest._ 
import org.junit.runner.RunWith 
import org.scalatest.junit.JUnitRunner 
import org.scalatest.matchers.ShouldMatchers 
import org.scalamock.ProxyMockFactory 
import org.scalamock.scalatest.MockFactory 

@RunWith(classOf[JUnitRunner]) 
class TurtleSpec extends FunSpec with MockFactory with ProxyMockFactory { 
    trait Turtle { 
    def turn(angle: Double) 
    } 

    val m = mock[Turtle] 
    m expects 'turn withArgs (10.0) 

    describe("A turtle-tester") { 
    it("should test the turtle") { 
     m.turn(10.0) 
    } 
    } 
} 

cevap

1

/resetExpectations testi, yani yapmanın en iyi yolu (ScalaTest yön) çalıştırmadan önce:

class TurtleSpec extends FunSpec with MockFactory with ProxyMockFactory with BeforeAndAfter { 

    before { 
    resetMocks() 
    resetExpectations() 
    } 

    ... 
}