2012-03-15 47 views
1

比方說,我有這樣的:如何使用Mockito模擬/存根方法本地依賴項?

class Dependency1 { 
    def methodD1 { } 
} 

class Dependency2 { 
    val dependency1 = new Dependency1 
} 

def myMethod() { 
    val a = new Dependency1 

    // I want to be able to stub this 
    val b = a.dependency1.methodD1() 
    ... 
} 

我想要做的事就像RR(紅寶石模擬庫):

any_instance_of(Dependency1) do | obj | 
    stub(obj) { "123" } # this would be like stub(obj) toReturn("123") with Mockito in Scala 
end 

我知道,是的Mockito的任何方法,但它是一個匹配器。我在尋找類似:

stub(anyInstanceOf(Dependency1).methodD1) toReturn("123") 

有沒有辦法來嘲笑/存根使用的Mockito/EasyMock的/ PowerMock/JMock的本地依賴?

我正在使用ScalaTest和MockitoSugar。

回答

相關問題