'How to do program keep running with checkpoint is failed

I am using SenerityBdd + Java. I have some scenarios with a lot steps. When a step gets failure then my program stopped. It's so difficult when doing debug steps because program always stops with failed checkpoint. I also soft assertion lib of java.

Do you have any idea to mark step FAILED but program keep running when having failed checkpoint?



Solution 1:[1]

You could use SoftAssertions from assertj library.

Adding on to Szprota21's comment, you would need to handle all exceptions.

Assuming that all exceptions are handled for a failing step, you could use below structure in your step definition class to implement soft assertion using assertj library.

import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import net.thucydides.core.annotations.Steps;

public class TestStepDefinitionClass {
    private SoftAssertions softAssertions;

    @Steps
    SomeClass SomeClass;
    
    // Before hook to initialize SoftAssertions object for every scenario
    @Before(order = 1)
    public void setUp() {
        softAssertions = new SoftAssertions();
    }

    // After hook to call assertAll() to invoke soft assertion for every scenario
    @After(order = 1)
    public void tearDown() {
        softAssertions.assertAll();
    }

    @Given("method1")
    public void method1() {
        // The below validation will fail, but since it is soft assertion, it will move on to the next step.
        softAssertions.assertThat(1).isEqualTo(2);
    }

    @Then("method2")
    public void pass2() {
        // assertion passed
        softAssertions.assertThat(2).isEqualTo(2);
    }

    @Then("method2")
    public void pass3() {
        // assertion passed
        softAssertions.assertThat(3).isEqualTo(3);
    }
}

Link for assertj maven repository

To learn about usages and common mistakes, follow Assertj documentation

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sanjay Gupta