在junit中使用softassert代替testng…?

d6kp6zgx  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(416)

我在testng中使用软Assert这里是我的代码

  1. if(!user.getUserreqmsg().isEmpty() ) {
  2. softAssert.assertEquals(createUser.getUsername_rqM(), user.getUserreqmsg());
  3. }
  4. if(!user.getUserlengthmsg().isEmpty()) {
  5. softAssert.assertEquals(createUser.getUsername_Min(), user.getUserlengthmsg());
  6. }

我想把它改成junit或者一些spring测试工具

pb3skfrl

pb3skfrl1#

junit中的软Assert可以实现为:
您可以使用:

  1. import org.assertj.core.api.SoftAssertions;

代码:

  1. SoftAssertions softAssertions = new SoftAssertions();
  2. softAssertions.assertThat(searchCriteriaPage.count()).isEqualTo(searchCriteria.getCount());
  3. softAssertions.assertAll();

maven依赖

  1. <!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
  2. <dependency>
  3. <groupId>org.assertj</groupId>
  4. <artifactId>assertj-core</artifactId>
  5. <version>3.18.1</version>
  6. </dependency>
展开查看全部

相关问题