내 상황 : 다음 클래스에 내가에 테스트 할 "HasSomething()"함수 : 그래서Rhino Mock을 사용하여 로컬 함수 호출을 모의하는 방법?
public class Something
{
private object _thing;
public virtual bool HasSomething()
{
if (HasSomething(_thing))
return true;
return false;
}
public virtual bool HasSomething(object thing)
{
....some algo here to check on the object...
return true;
}
}
, 내가 이렇게 될 내 테스트를 작성 :
public void HasSomethingTest1()
{
MockRepository mocks = new MockRepository();
Something target = mocks.DynamicMock(typeof(Something)) as Something;
Expect.Call(target.HasSomething(new Object())).IgnoreArguments().Return(true);
bool expected = true;
bool actual;
actual = target.HasSomething();
Assert.AreEqual(expected, actual);
}
테스트가 올바르게 작성 되었습니까? 예상대로 결과를 얻을 수 없으므로 도와주세요. "HasSomething (객체)"는 그런 식으로 조롱 할 수 없습니다. 그것은 기대치에 못 미치는 것으로 '사실'을 돌려주지 않았다.
감사합니다.
등의 조롱 객체가 SUT로 전달되어야 스터브 부분 모의 전환. something.HasSomething (mockedObject); –