Skip to content

Commit

Permalink
Fix #3141 #2920 - Make Junit recognise and report assertion failures (#…
Browse files Browse the repository at this point in the history
…3158)

* Make Junit recognise and report assertion failures

* resolved formatting issues

---------

Co-authored-by: Dipak Bachhav <[email protected]>
  • Loading branch information
bachhavdipak and dipakbachhav authored Jul 10, 2023
1 parent 8c2e5ff commit c32b68e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ public static void throwExceptionsImmediately() {
throwExceptionsImmediately = true;
}

public static boolean shouldThrowExceptionsImmediately() {
return throwExceptionsImmediately = true;
}

public static boolean shouldThrowErrorsImmediately() {
return throwExceptionsImmediately;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ private void notifyOfStepFailure(final Object object, final Method method, final
else {
StepEventBus.getParallelEventBus().stepFailed(failure);
}
if (shouldThrowExceptionImmediately()) {
if (shouldThrowExceptionsImmediately()) {
finishAnyCucumberSteps();
throw cause;
}
Expand All @@ -623,8 +623,8 @@ private void finishAnyCucumberSteps() {
}
}

private boolean shouldThrowExceptionImmediately() {
return Serenity.shouldThrowErrorsImmediately();
private boolean shouldThrowExceptionsImmediately() {
return Serenity.shouldThrowExceptionsImmediately();
}

private void notifyStepStarted(final Object object, final Method method, final Object[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package net.serenitybdd.junit5.samples.integration.displayName;

import net.serenitybdd.junit5.SerenityJUnit5Extension;
import org.junit.jupiter.api.DisplayName;
import net.serenitybdd.junit5.samples.integration.displayName.steps.TestExample;
import net.thucydides.core.annotations.Steps;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;
Expand All @@ -12,11 +13,16 @@
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
public class JUnit5DisplayNameExample {

@Steps
TestExample testExample;


@Test
void test_spaces_ok() {
}

@Test
void test_spaces_fail() {
testExample.test_spaces_fail();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.serenitybdd.junit5.samples.integration.displayName.steps;

import net.thucydides.core.steps.ScenarioSteps;
import org.junit.Assert;

public class TestExample extends ScenarioSteps {
public void test_spaces_fail() {
Assert.assertTrue(false);
}
}

0 comments on commit c32b68e

Please sign in to comment.