Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test class doesn't fail after the first test method failure #3545

Closed
johnysv opened this issue Nov 6, 2023 · 2 comments
Closed

Test class doesn't fail after the first test method failure #3545

johnysv opened this issue Nov 6, 2023 · 2 comments

Comments

@johnysv
Copy link

johnysv commented Nov 6, 2023

I am using SerenityBDD with JUnit 5. I need my whole test class to fail when one of my @Test methods fails. My test looks like:

package com.xxx;

import com.xxx.frp.steps.*;
import com.xxx.frp.steps.configuration.TestConfiguration;
import lombok.extern.slf4j.Slf4j;
import net.serenitybdd.annotations.*;
import net.serenitybdd.junit.spring.integration.SpringIntegrationMethodRule;
import net.serenitybdd.junit5.SerenityJUnit5Extension;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.openqa.selenium.WebDriver;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.test.context.ContextConfiguration;

import static com.xxx.xx.utils.Utils.waitForNSeconds;

@Slf4j
@ExtendWith(SerenityJUnit5Extension.class)
@ContextConfiguration(classes = TestConfiguration.class)
@EnableRetry
@TestMethodOrder(MethodOrderer.MethodName.class)

public class UJTest {

    @Rule
    public SpringIntegrationMethodRule springIntegrationMethodRule = new SpringIntegrationMethodRule();
    public static Boolean previousTestPassed = true;
    @Rule
    public TestWatcher watchman = new TestWatcher() {
        @Override
        protected void failed(Throwable e, Description description) {
            LOG.info(description.toString());
            previousTestPassed = false;
        }
    };

    @Managed(clearCookies = ClearCookiesPolicy.Never)
    public WebDriver webdriver;

    @Steps
    public LoginSteps loginSteps;

    @Test
    @Tags({@Tag("newe2eLargea"), @Tag("b"), @Tag("c")})
    @Title("HierarchyUploadAndLogin:")
    public void UserJourneyPart1_HierarchyUploadAndLogin() throws Exception {
        loginSteps.loginAsGroupManager();
    }

    @Test
    @Tags({@Tag("newe2eLargea"), @Tag("b"), @Tag("c")})
    @Title("two")
    public void UserJourneyPart2_secondPart() throws Exception {
        Assumptions.assumeTrue(previousTestPassed, "Previous test failed, hence ignored");
        loginSteps.loginAsGroupManager();
        Assert.assertTrue(false);


    }

    @Test
    @Tags({@Tag("newe2eLargea"), @Tag("b"), @Tag("c")})
    @Title("three")
    public void UserJourneyPart3_thirdPart() throws Exception {
        Assumptions.assumeTrue(previousTestPassed, "Previous test failed, hence ignored");
        loginSteps.loginAsGroupManager();

    }

}

But even though my second test fails, JUnit executes the third one. Is there anyway I could achieve that in JUnit 5?

@marcphilipp
Copy link
Member

marcphilipp commented Nov 6, 2023

Partially, yes. We call the feature "scenario tests", and there's an open issue with some existing extension that gets you there, most of the way: #48

@marcphilipp
Copy link
Member

marcphilipp commented Nov 6, 2023

@marcphilipp marcphilipp marked this as a duplicate of #48 Nov 6, 2023
@marcphilipp marcphilipp closed this as not planned Won't fix, can't repro, duplicate, stale Nov 6, 2023
@sbrannen sbrannen changed the title Test doesn't fails at the first test failure Test class doesn't fail after the first test method failure Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants