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

Usage with AssertJ possible? #56

Open
hansjoergkeser opened this issue Mar 6, 2020 · 4 comments
Open

Usage with AssertJ possible? #56

hansjoergkeser opened this issue Mar 6, 2020 · 4 comments

Comments

@hansjoergkeser
Copy link

hansjoergkeser commented Mar 6, 2020

Hi Artem,

nice extension, it works good with JUnit 5 Assertions.
Unfortunately it does not seem to work with JUnit 5 and AssertJ. I configured the RepeatedIfExceptionsTest annotation with
exceptions = Error.class
or
AssertionFailedError
AssertionError

parameter, but each test is only run once.

@artsok
Copy link
Owner

artsok commented Apr 12, 2020

Hi, I unfortunately don't have time to fixed it. If u could, make PR do it please.

@perlun
Copy link

perlun commented Oct 15, 2021

@hansjoergkeser It would be interesting to hear more about this. We are also using AssertJ with our tests, but they seem to play well with rerunner-jupiter AFAICT. Note though that this is not with RepeatedIfExceptionsTest but with ParameterizedRepeatedIfExceptionsTest:

image

Would you mind supplying a minimal reproducible example that illustrates the problem you're seeing, if it's still active?

@hansjoergkeser
Copy link
Author

hansjoergkeser commented Nov 10, 2021

@perlun thx for the hint. My description was not detailed enough: I meant AssertJ SoftAssertions. They collect all AssertionFailedError and throw one AssertJMultipleFailuresError in the end. I unsuccessfully tried to configure the rerunner accordingly

`package hajo;

import io.github.artsok.RepeatedIfExceptionsTest;
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.assertj.core.error.AssertJMultipleFailuresError;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;

@ExtendWith(SoftAssertionsExtension.class)
public class MyTests {

@RepeatedIfExceptionsTest(repeats = 3)
void testWithJUnit() {
    assertFalse(true, "Fail by JUnit ´hard´ assertion: org.opentest4j.AssertionFailedError");
}

@RepeatedIfExceptionsTest(repeats = 3)
void testWithAssertJ_Soft_Default(SoftAssertions softAssertions) {
    softAssertions.assertThat(1)
            .as("Fail by AssertJ ´soft´ assertion: org.assertj.core.error.AssertJMultipleFailuresError")
            .isEqualTo(2);
}

@RepeatedIfExceptionsTest(repeats = 3, exceptions = AssertJMultipleFailuresError.class)
void testWithAssertJ_Soft(SoftAssertions softAssertions) {
    softAssertions.assertThat(1)
            .as("Fail by AssertJ ´soft´ assertion: org.assertj.core.error.AssertJMultipleFailuresError")
            .isEqualTo(2);
}

@RepeatedIfExceptionsTest(repeats = 3)
void testWithAssertJ_Hard() {
    assertThat(1)
            .as("Fail by AssertJ ´hard´ assertion: org.opentest4j.AssertionFailedError")
            .isEqualTo(2);
}

}
`

@hansjoergkeser
Copy link
Author

If I have time ill try to investigate how these soft assertions exactly work.
https://github.com/hansjoergkeser/rerunner-jupiter-arstok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants