-1
因此,這裏的情景單元測試 - 我如何從受保護的方法存根布爾值?
public class Report {
public void Generate {
if (!isValidDate) {
return;
}
//calling other method
}
protected boolean isValidDate() {
boolean isValid = true;
//some logic here to change to false
return isValid;
}
}
而在我的測試中,我有這樣的,因爲我想設置的布爾值是真實的。
@InjectMocks
Report report;
@Before
public void setUp() throws Exception {
Whitebox.setInternalState(report, "isValidParameters", true);
}
@Test
public void testReport() throws Exception {
//test logic to be added here
}
然後我得到了RuntimeException:無法設置私人領域的內部狀態。有人可以幫助我如何在這裏爲我的測試設置受保護方法的布爾值嗎? TIA