-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