これは、JUnit と JMock でテストしようとしているコントローラー メソッドです。
public String myMethod(ModelMap model, Principal principal,
@PathVariable MyObject obj) {
if (obj != null) {
Student student = getStudent(principal);
if (check(obj, student)) {
model.addAttribute(student).addAttribute(obj);
return "page";
}
}
return REDIR;
}
private boolean check(MyObject obj, Student student) {
return student.getStudentNumber().longValue() == obj.getStudent().getStudentNumber().longValue();
}
私のテスト
final StudentService studentService = context.mock(StudentService.class);
public void test() throws Exception {
ModelMap model = new ModelMap();
final MyObject = new myObject();
context.checking(new Expectations() {
{
oneOf(studentService).getByNumber(SecurityHelper.getStudentNumberOf(Helper.getTestPrincipal()));
will(returnValue(mockStudent));
}
});
controller.myMethod(model, Helper.getTestPrincipal(), obj);
}
テストを実行すると、NullPointerExeption
チェック方法のポイントを取得します。それはどこから来たのですか?ちょっと期待外れだからかな?Student と obj はモック可能なインターフェイスではありません。私はこれが初めてです。この種のテスト エラーを追跡する最良の方法はどれですか?