我如何測試在SomeClass中動態創建的這個ValueObject,而不使用PowerMock等進行存根?如何在單元測試時獲取新對象的句柄?
class ValueOBject {
private String x, y;
getters
setters
}
class SomeClass {
public void foo() {
ValueObject vo = new ValueObject();
vo.setX("some string 1");
vo.setY("some string 2");
faa(vo);
}
public void faa(ValueObject vo) {
// do some more logic on vo here
}
}
class SomeClassTest extends TestCase{
public void testFoo() {
SomeClass s = new SomeClass();
s.foo();
// HOW TO DO THIS?
verify(faa(VAlueObject that is created during foo's run));
}
}
我不想使用PowerMockito或類似的庫返回一個對象嘲笑! 相反的真實對象那是實際方法foo()的執行期間創建的:
// DONT WANT A MOCKED OBJECT
// @Mock
// private ValueOBject vo;
// henNew(GetEmailInformation.class).withNoArguments().thenReturn(getEmailInformation);
訪問者會有幫助嗎? – chessofnerd