Monday, August 10, 2009

Scala & EasyMock take II

Now that I'm using Scala's Manifest more, here is how my testing with EasyMock code looks like. Instead of

val mocked1 = EasyMock.createMock(classOf[MyClazz])
val mocked2 = EasyMock.createMock(classOf[MyOtherClazz])
Its
val mocked1 = mock[MyClazz]
val mocked2 = mock[MyOtherClazz]
And
def mock[A](implicit m: Manifest[A]) = EasyMock.createMock(m.erasure).asInstanceOf[A]
Running the test using
run(mocked1, mocked2){
//code using mocks here
}
And
def run(mocks : AnyRef*)(block : => Unit){
replay(mocks : _*)
block
verify(mocks : _*)
reset(mocks : _*)
}

Creative Commons License This work by Eishay Smith is licensed under a Creative Commons Attribution 3.0 Unported License.