-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