断言软断言抛出异常

时间:2021-04-29 07:17:09

标签: assertj

Assertj 软断言抛出异常,它只执行第一个断言,然后失败。 任何帮助将不胜感激。

    org.assertj.core.api.SoftAssertionError: 
    The following assertion failed:
    1) 
    Expected size:<8> but was:<7> in:
    <"seleniu">
    at SpringTest.lambda$stringTest$0(SpringTest.java:15)
        at org.assertj.core.api.AbstractSoftAssertions.throwsBestMultipleAssertionsError(AbstractSoftAssertions.java:198)
        at org.assertj.core.api.SoftAssertions.assertAll(SoftAssertions.java:131)
        at org.assertj.core.api.SoftAssertions.assertSoftly(SoftAssertions.java:159)

公共类 SpringTest {

@Test(dataProvider = "getData")
public void stringTest(String input){

    //Soft assertions.
    assertSoftly(softAssertions -> {
        softAssertions.assertThat(input)
                .hasSize(8)
                .startsWith("se")
                .doesNotContain("api")
                .doesNotContainAnyWhitespaces()
                .containsOnlyOnce("i");
    });

}

@DataProvider
public Object[] getData(){
    return new String[]{
            "seleniu",
            "selenide"
    };
}

}

0 个答案:

没有答案
相关问题