[英]I am trying to write a JUnit test case for a method to insert timesheet which takes a parameter as employee Id. How should I try?
我試圖在時間表類型中創建一個新對象並分配值,但是我有一個方法方法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);
}
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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.