当前位置: 首页 > 知识库问答 >
问题:

在cucumber中使用软断言

吕永嘉
2023-03-14

试图看到一个在Cucumber中使用软断言的工作示例。我有以下简单的特性和步骤定义,我故意使一些验证失败,但cucumber测试仍然显示“通过”。我是不是做错什么了。

@给定(“^I have a Scenary for Soft Assert$”)public void i_have_a_scenario_for_soft_assert()throwsable{

    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");
    

}

共有1个答案

皇甫俊雅
2023-03-14

sa.assertThat()方法将实际值作为参数,并返回一个必须用可用方法之一检查的断言对象。在您的示例中,必须使用IsEqualToIngrouningCase(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");
    

}
 类似资料:
  • 问题内容: 我有一个需要测试的响应式网站。如果网站转到平板电脑的窗口大小,我希望测试检查是否有水平滚动条。根据设计,它们永远不会出现在平板电脑上。 是否有人使用Selenium Webdriver Java Cucumber拥有一段伪代码来断言水平滚动条的存在? 问题答案: 您可以使用以下方法进行测试: 垂直滚动条: 水平滚动条:

  • 我编写了一个JUnit测试,使用Mockito和PowerMock模拟一些类。我试图将其转换为cucumber测试,但静态的PowerMock特性不起作用。 两类相关cucumber的提取物: 虽然这段代码在JUnit测试中工作,但它在这里失败了--它进入了方法,该方法应该被模拟,然后通过在其中执行代码而失败。我试着加了几行: 对上述两个类(当然,我不能在类中使用,因为它已经有一个注释),但这不会

  • 我有一个webservice操作,其中我将获得SAML断言作为请求体的一部分。我跟踪XSD: saml:断言是指:< br>

  • 下面是TestNG框架中的一个示例断言方法。 下面是fail方法。 在TestNG中是否有一个内置的方法来执行软断言。如果没有,实现这一点的理想方式是什么。

  • 我以标准方式在Java中使用断言,在IDE中启用它们。因此,它们不是产品发布的一部分。最近,我看到了<code>抛出新的断言错误()的代码示例 我的猜测是,主要区别在于断言的可选性,因此它们不会减慢生产性能,因此它们可以在代码中经常发生,但修复用户报告的几乎无法重现的错误更难。 对于,正好相反。 我还发现在代码中不应该执行的地方更实用,而不是使用。特别是如果需要返回值。例如: 我的推理正确吗 两种

  • 我似乎有一些问题与耙子和我的cucumber特征文件。 这是詹金斯的命令。它指定了我直接放在。/features目录,所以testjson.feature就在那里。 Rakefile看起来像这样: 这非常简单,但在 Jenkins 的控制台输出中,我得到: 这告诉我它没有找到功能文件,对吗? 当我转到功能文件上方的目录并运行Cucumber时,测试就可以了! 所以,很明显我的Rake文件出错了。有