@Test
public void testUpdateByPrimaryKey() {
TbItem item = tbItemMapper.selectByPrimaryKey(536563L);
// 更新日期
Date now = new Date();
item.setUpdated(now);
tbItemMapper.updateByPrimaryKey(item);
TbItem item2 = tbItemMapper.selectByPrimaryKey(536563L);
Assert.assertEquals(item2.getUpdated().getTime(), now.getTime());
}
单元测试报错:
java.lang.AssertionError: expected:<1511939879000> but was:<1511939879936>
....
如上所示,前后2次进行select,中间进行了update,但是2次select获取的对象值是一样的,也就是中间的update没有提交,整个测试方法就是一个事务单元,只有整个方法运行完了,该事务才会提交?不知我的理解有没有错误呢?还有,类似这种update的单元测试怎么写比较好?