Skip to content

Commit

Permalink
TMS-28135: Fixed running tests in case of a failed setup for JUnit5. (#…
Browse files Browse the repository at this point in the history
…161)

Co-authored-by: pavel.butuzov <[email protected]>
  • Loading branch information
PavelButuzov and pavel.butuzov authored Nov 12, 2024
1 parent 898d70c commit c0938ba
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.3.7
version=2.3.8

org.gradle.daemon=true
org.gradle.parallel=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class BaseJunit5Listener implements Extension, BeforeAllCallback, AfterAl
private final AdapterManager adapterManager;
private final ThreadLocal<ExecutableTest> executableTest = ThreadLocal.withInitial(ExecutableTest::new);
private final ThreadLocal<String> launcherUUID = ThreadLocal.withInitial(() -> UUID.randomUUID().toString());
private Throwable BeforeAllThrowable;
private Throwable BeforeEachThrowable;

public BaseJunit5Listener() {
adapterManager = Adapter.getAdapterManager();
Expand Down Expand Up @@ -63,6 +65,13 @@ public void interceptBeforeAllMethod(
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext
) {
if (BeforeAllThrowable != null)
{
invocation.skip();

return;
}

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Intercept before all: {}", invocationContext.getExecutable().getName());
}
Expand All @@ -75,6 +84,8 @@ public void interceptBeforeAllMethod(
invocation.proceed();
adapterManager.updateFixture(uuid, result -> result.setItemStatus(ItemStatus.PASSED));
} catch (Throwable throwable) {
BeforeAllThrowable = throwable;

adapterManager.updateFixture(uuid, result -> result.setItemStatus(ItemStatus.FAILED));
}

Expand All @@ -95,6 +106,13 @@ public void interceptBeforeEachMethod(
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext
) {
if (BeforeAllThrowable != null || BeforeEachThrowable != null)
{
invocation.skip();

return;
}

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Intercept before each: {}", invocationContext.getExecutable().getName());
}
Expand All @@ -114,6 +132,8 @@ public void interceptBeforeEachMethod(
invocation.proceed();
adapterManager.updateFixture(uuid, result -> result.setItemStatus(ItemStatus.PASSED));
} catch (Throwable throwable) {
BeforeEachThrowable = throwable;

adapterManager.updateFixture(uuid, result -> result.setItemStatus(ItemStatus.FAILED));
}

Expand Down Expand Up @@ -145,6 +165,7 @@ public void interceptTestTemplateMethod(
adapterManager.updateClassContainer(Utils.getHash(invocationContext.getTargetClass().getName()),
container -> container.getChildren().add(uuid));

callFixtureThrowable();
invocation.proceed();
}

Expand Down Expand Up @@ -193,6 +214,7 @@ public void interceptTestMethod(
adapterManager.updateClassContainer(Utils.getHash(invocationContext.getTargetClass().getName()),
container -> container.getChildren().add(uuid));

callFixtureThrowable();
invocation.proceed();
}

Expand Down Expand Up @@ -284,6 +306,15 @@ public void interceptAfterEachMethod(
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext
) {
if (BeforeEachThrowable != null || BeforeAllThrowable != null)
{
BeforeEachThrowable = null;

invocation.skip();

return;
}

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Intercept after each: {}", invocationContext.getExecutable().getName());
}
Expand All @@ -310,6 +341,15 @@ public void interceptAfterAllMethod(
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext
) {
if (BeforeAllThrowable != null)
{
BeforeAllThrowable = null;

invocation.skip();

return;
}

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Intercept after all: {}", invocationContext.getExecutable().getName());
}
Expand All @@ -332,4 +372,17 @@ private ExecutableTest refreshContext() {
executableTest.remove();
return executableTest.get();
}

private void callFixtureThrowable() throws Throwable
{
if (BeforeAllThrowable != null)
{
throw BeforeAllThrowable;
}

if (BeforeEachThrowable != null)
{
throw BeforeEachThrowable;
}
}
}

0 comments on commit c0938ba

Please sign in to comment.