JUnit是由 Erich Gamma 和 Kent Beck 编写的一个回归测试框架(regression testing framework)。Junit测试是程序员测试,即所谓白盒测试,因为程序员知道被测试的软件如何(How)完成功能和完成什么样(What)的功能。Junit是一套框架,继承TestCase类,用Junit进行自动测试。
(1) 在删除的操作的中Junit思路如下:
a. 先插入数据,利用类似下面的语句插入数据。
a. 先插入数据,利用类似下面的语句插入数据。
jdbcTemplate.execute(
"INSERT INTO SUP_PO_APPLY_SOFT_Notice" +
" (APPLYFORM_ID," +
" USERID," +
" CREATEDTIME," +
" LASTMODIFIEDBY," +
" LASTMODIFIEDTIME," +
" USERGROUPS" +
" )" +
"VALUES ('" + applyFormId + "', " +
" '" + userId + "', " +
" sysdate, " +
" '" + lastModifiedBy + "', " +
" sysdate, " +
" '" + userGroups + "')");
b.再利用你需要测试删除的方法,删除刚刚创建的数据。
poApplyDao.delPoApplyFormToNoticeByFormId(applyFormId);
long result = jdbcTemplate.queryForLong(
"select count(1) from sup_po_apply_soft_Notice where applyform_id = '"+applyFormId+"'");
Assert.assertEquals(0, result);
(3)查询数据的操作的Junit写法如下。
思路一: a.先考虑构造一些数据并将其插入到表中。同时留意记下插入的关键值。
jdbcTemplate.execute("INSERT INTO .....
b.再将刚刚插入的某些值作为查询条件,传入到查询操作的方法中,看看是否有结果展现。
Assert.assertNotNull(af2us);
Assert.assertEquals(1, af2us.size());
思路二:直接在数据库中找到已经存在的数据,作为查询条件。在调用函数来,完成查询。
public void testFindSwInfoDocListById_02()
{
IPoSwInfoDTO poSwInfoDto = new PoSwInfoDTO();
poSwInfoDto.setPoNo("0006160906050");
poSwInfoDto.setNlsLang("zh");
//iPoSwInfoDto.setPoNo("0006160906050");
List<ISwInfoDocDTO> resultList = poApplyDao.findSwInfoDocListById(poSwInfoDto);
Assert.assertNotNull(resultList);