【发布时间】:2017-09-29 23:36:57
【问题描述】:
所以这里是场景
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;
}
}
在我的测试中,我有这个,因为我想将布尔值设置为 true。
@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: Unable to set internal state on a private field。有人可以帮助我如何在这里为我的测试设置该受保护方法的布尔值吗? TIA
【问题讨论】:
标签: unit-testing junit mockito powermockito