Skip to content

Commit

Permalink
Merge pull request #380 from TikhomirovSergey/allure_do_not_report
Browse files Browse the repository at this point in the history
0.24.1-ALPHA
  • Loading branch information
TikhomirovSergey authored Nov 3, 2022
2 parents 719c818 + 56aea11 commit 1832ac4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.lang.reflect.Method;

import static ru.tinkoff.qa.neptune.allure.jupiter.bridge.NeptuneAllureExcludeTest.getCurrentTestClass;
import static ru.tinkoff.qa.neptune.allure.lifecycle.ItemsToNotBeReported.excludeFixtureIfNecessary;
import static ru.tinkoff.qa.neptune.allure.lifecycle.ItemsToNotBeReported.excludeTestResultIfNecessary;

Expand All @@ -19,9 +18,10 @@ public ExcludeFromAllureReportExtension() {

private <T> T checkCurrentLifeCycleItemAndProceed(Invocation<T> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext,
boolean isTest) throws Throwable {
var method = invocationContext.getExecutable();
var target = getCurrentTestClass();
var target = extensionContext.getRequiredTestClass();

if (isTest) {
excludeTestResultIfNecessary(target, method);
Expand All @@ -37,48 +37,48 @@ private <T> T checkCurrentLifeCycleItemAndProceed(Invocation<T> invocation,
public void interceptBeforeAllMethod(InvocationInterceptor.Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) throws Throwable {
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, false);
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, extensionContext, false);
}

@Override
public void interceptAfterAllMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) throws Throwable {
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, false);
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, extensionContext, false);
}

@Override
public void interceptBeforeEachMethod(InvocationInterceptor.Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) throws Throwable {
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, false);
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, extensionContext, false);
}

@Override
public void interceptAfterEachMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) throws Throwable {
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, false);
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, extensionContext, false);
}

@Override
public void interceptTestMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) throws Throwable {
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, true);
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, extensionContext, true);
}

@Override
public <T> T interceptTestFactoryMethod(Invocation<T> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) throws Throwable {
return checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, true);
return checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, extensionContext, true);
}

@Override
public void interceptTestTemplateMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext) throws Throwable {
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, true);
checkCurrentLifeCycleItemAndProceed(invocation, invocationContext, extensionContext, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.AllureResultsWriter;
import io.qameta.allure.FileSystemResultsWriter;
import org.junit.platform.engine.TestExecutionResult;
import org.junit.platform.engine.support.descriptor.ClassSource;
import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.TestIdentifier;
import ru.tinkoff.qa.neptune.allure.lifecycle.NeptuneResultWriter;

import java.nio.file.Paths;
import java.util.LinkedHashSet;
import java.util.LinkedList;

import static io.qameta.allure.Allure.setLifecycle;
import static io.qameta.allure.util.PropertiesUtils.loadAllureProperties;
import static java.util.Optional.ofNullable;

public class NeptuneAllureExcludeTest implements TestExecutionListener {

private static final NeptuneResultWriter NEPTUNE_RESULT_WRITER = init();
private static final ThreadLocal<LinkedHashSet<Class<?>>> TEST_CLASS_THREAD_LOCAL = new ThreadLocal<>();

private static NeptuneResultWriter init() {
var properties = loadAllureProperties();
Expand All @@ -35,48 +28,4 @@ private static NeptuneResultWriter init() {
static void changeResultWriter(AllureResultsWriter writer) {
NEPTUNE_RESULT_WRITER.setResultWriter(writer);
}

@Override
public void executionStarted(final TestIdentifier testIdentifier) {
var source = testIdentifier.getSource().orElse(null);

if (source instanceof ClassSource) {
var clazz = ((ClassSource) source).getJavaClass();
var queue = ofNullable(TEST_CLASS_THREAD_LOCAL.get()).orElseGet(() -> {
var newQueue = new LinkedHashSet<Class<?>>();
TEST_CLASS_THREAD_LOCAL.set(newQueue);
return newQueue;
});

if (queue.isEmpty() || !queue.contains(clazz)) {
queue.add(clazz);
}
}
}

@Override
public void executionFinished(final TestIdentifier testIdentifier,
final TestExecutionResult testExecutionResult) {
var source = testIdentifier.getSource().orElse(null);

if (source instanceof ClassSource) {
var queue = TEST_CLASS_THREAD_LOCAL.get();
if (!queue.isEmpty()) {
queue.remove(((ClassSource) source).getJavaClass());
}

if (queue.isEmpty()) {
TEST_CLASS_THREAD_LOCAL.remove();
}
}
}

public static Class<?> getCurrentTestClass() {
return ofNullable(TEST_CLASS_THREAD_LOCAL.get()).map(set -> {
if (set.isEmpty()) {
return null;
}
return new LinkedList<>(set).getLast();
}).orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
junit.jupiter.extensions.autodetection.enabled=true
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.classes.default=concurrent
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.config.dynamic.factor=5
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

ext {
globalVersion = '0.24.0-ALPHA'
globalVersion = '0.24.1-ALPHA'
}

repositories {
Expand Down

0 comments on commit 1832ac4

Please sign in to comment.