我试图在时间表类型中创建一个新对象并分配值。但是我有一个方法调用insertTimesheet,它需要有employeeId。由于时间表对象中的employeeId没有此类值,因此测试失败。
@Test
public void testInsertTimesheet() {
Timesheet expectedToSave = new Timesheet( 1001 ,"2019-01-10", "2019-01-05", "comment section is this ", "saved", null, null);
int actualInsertData = timesheetRepository.insertTimesheet(expectedToSave, 100789);
Assertions.assertEquals(expectedToSave, actualInsertData);
}
答案 0 :(得分:0)
JdbcTemplate.update()
方法将返回生效的行数。如果未成功插入,将抛出DataAccessException
异常。
@Test
public void testInsertTimesheet() {
Timesheet expectedToSave = new Timesheet( 1001 ,"2019-01-10", "2019-01-05", "comment section is this ", "saved", null, null);
int actualInsertData = timesheetRepository.insertTimesheet(expectedToSave, 100789); //In here number of effected rows is 1 so insertTimeSheet() will return 1
Assert.assertEquals(1, actualInsertData); //expected value is 1
}