在junit中使用softassert代替testng…?

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

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

if(!user.getUserreqmsg().isEmpty() ) {

               softAssert.assertEquals(createUser.getUsername_rqM(), user.getUserreqmsg());
            }
            if(!user.getUserlengthmsg().isEmpty()) {
                softAssert.assertEquals(createUser.getUsername_Min(), user.getUserlengthmsg());
            }

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

pb3skfrl

pb3skfrl1#

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

import org.assertj.core.api.SoftAssertions;

代码:

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

maven依赖

<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.18.1</version>

    </dependency>

相关问题