0
点赞
收藏
分享

微信扫一扫

MyBatis-Plus_断言


MyBatis-Plus 之断言

文章目录

  • ​​1. 断言代码:​​
  • ​​2. 源码:​​
  • ​​3. 释义:​​
  • ​​4. 举个栗子:​​
  • ​​5. 异常信息:​​
  • ​​6. 控制台输出定位​​
  • ​​7. 查看数据库:​​

1. 断言代码:

Assert.assertEquals(5, userList.size());

2. 源码:

static public void assertEquals(long expected, long actual) {
assertEquals(null, expected, actual);
}

3. 释义:

前面的第一个参数5表示你设置的一个值或者数 后面代码实际的数据数 如果一样就通过,如果不通过,就会定位在这一行代码。

4. 举个栗子:

    1.数据库的数据信息6条
2. 断言你写的5条,但实际有6条
3. 控制台就会定位在这一行

5. 异常信息:

at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit.Assert.assertEquals(Assert.java:645)
at org.junit.Assert.assertEquals(Assert.java:631)
at com.gblfy.mp.mybatisplus.samplesquickstart.mapper.UserMapperTest.selectList(UserMapperTest.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

6. 控制台输出定位

MyBatis-Plus_断言_MyBatis-Plus

7. 查看数据库:

6条数据

MyBatis-Plus_断言_MyBatis-Plus_02


从上面可以看出,数据库数据信息数量和设置的数量不一致,触发断言。


举报

相关推荐

0 条评论