账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    spring单元测试中,为什么update后获取的值还是旧值呢?
    31
    0
    @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的单元测试怎么写比较好?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 一半爱情 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    网站公告
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部