将 SoftAssertion 与黄瓜一起使用
Using SoftAssertion with cucumber
试图查看有关在黄瓜中使用软断言的工作示例。我有以下简单的功能和步骤定义,我故意让一些验证失败但是黄瓜测试仍然显示“通过”。我是不是做错了什么。
@Given("^我有一个软断言 $" 的场景)
public void i_have_a_scenario_for_soft_assert() 抛出 Throwable {
System.out.println("Inside the given of soft assestion.. All Good");
}
@When("^I validate the first step for soft assertion$")
public void i_validate_the_first_step_for_soft_assertion() throws Throwable {
sa = new SoftAssertions();
System.out.println("Executing the FIRST");
sa.assertThat("bal".equalsIgnoreCase("BAL"));
System.out.println("Executing the SECOND");
sa.assertThat("bal".equalsIgnoreCase("AM"));
System.out.println("Executing the THIRD");
sa.assertThat("123".equalsIgnoreCase("321"));
}
@And("^i validate the second step for soft assertion$")
public void i_validate_the_second_step_for_soft_assertion() throws Throwable {
System.out.println("Second validation.. All Good");
}
@Then("^I complete my validation for soft assertion example$")
public void i_complete_my_validation_for_soft_assertion_example() throws Throwable {
sa.assertAll();
System.out.println("Final Validation.. All Good");
}
sa.assertThat() 方法将实际值作为参数,returns 一个必须使用可用方法之一检查的断言对象。在您的示例中,必须使用 isEqualToIgnoringCase(expected) 方法对其进行检查。
@Given("^I have a scenario for Soft assert$")
public void i_have_a_scenario_for_soft_assert() throws Throwable {
System.out.println("Inside the given of soft assestion.. All Good");
}
@When("^I validate the first step for soft assertion$")
public void i_validate_the_first_step_for_soft_assertion() throws Throwable {
sa = new SoftAssertions();
System.out.println("Executing the FIRST");
sa.assertThat("bal").isEqualToIgnoringCase("BAL");
System.out.println("Executing the SECOND");
sa.assertThat("bal").isEqualToIgnoringCase("AM");
System.out.println("Executing the THIRD");
sa.assertThat("123").isEqualToIgnoringCase("321");
}
@And("^i validate the second step for soft assertion$")
public void i_validate_the_second_step_for_soft_assertion() throws Throwable {
System.out.println("Second validation.. All Good");
}
@Then("^I complete my validation for soft assertion example$")
public void i_complete_my_validation_for_soft_assertion_example() throws Throwable {
sa.assertAll();
System.out.println("Final Validation.. All Good");
}
试图查看有关在黄瓜中使用软断言的工作示例。我有以下简单的功能和步骤定义,我故意让一些验证失败但是黄瓜测试仍然显示“通过”。我是不是做错了什么。
@Given("^我有一个软断言 $" 的场景) public void i_have_a_scenario_for_soft_assert() 抛出 Throwable {
System.out.println("Inside the given of soft assestion.. All Good");
}
@When("^I validate the first step for soft assertion$")
public void i_validate_the_first_step_for_soft_assertion() throws Throwable {
sa = new SoftAssertions();
System.out.println("Executing the FIRST");
sa.assertThat("bal".equalsIgnoreCase("BAL"));
System.out.println("Executing the SECOND");
sa.assertThat("bal".equalsIgnoreCase("AM"));
System.out.println("Executing the THIRD");
sa.assertThat("123".equalsIgnoreCase("321"));
}
@And("^i validate the second step for soft assertion$")
public void i_validate_the_second_step_for_soft_assertion() throws Throwable {
System.out.println("Second validation.. All Good");
}
@Then("^I complete my validation for soft assertion example$")
public void i_complete_my_validation_for_soft_assertion_example() throws Throwable {
sa.assertAll();
System.out.println("Final Validation.. All Good");
}
sa.assertThat() 方法将实际值作为参数,returns 一个必须使用可用方法之一检查的断言对象。在您的示例中,必须使用 isEqualToIgnoringCase(expected) 方法对其进行检查。
@Given("^I have a scenario for Soft assert$")
public void i_have_a_scenario_for_soft_assert() throws Throwable {
System.out.println("Inside the given of soft assestion.. All Good");
}
@When("^I validate the first step for soft assertion$")
public void i_validate_the_first_step_for_soft_assertion() throws Throwable {
sa = new SoftAssertions();
System.out.println("Executing the FIRST");
sa.assertThat("bal").isEqualToIgnoringCase("BAL");
System.out.println("Executing the SECOND");
sa.assertThat("bal").isEqualToIgnoringCase("AM");
System.out.println("Executing the THIRD");
sa.assertThat("123").isEqualToIgnoringCase("321");
}
@And("^i validate the second step for soft assertion$")
public void i_validate_the_second_step_for_soft_assertion() throws Throwable {
System.out.println("Second validation.. All Good");
}
@Then("^I complete my validation for soft assertion example$")
public void i_complete_my_validation_for_soft_assertion_example() throws Throwable {
sa.assertAll();
System.out.println("Final Validation.. All Good");
}