diff --git a/junitperf-core/src/main/java/com/github/noconnor/junitperf/data/EvaluationContext.java b/junitperf-core/src/main/java/com/github/noconnor/junitperf/data/EvaluationContext.java index 56d9ff0..1784aac 100644 --- a/junitperf-core/src/main/java/com/github/noconnor/junitperf/data/EvaluationContext.java +++ b/junitperf-core/src/main/java/com/github/noconnor/junitperf/data/EvaluationContext.java @@ -3,6 +3,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.Maps.newTreeMap; +import static java.lang.System.nanoTime; import static java.util.Collections.emptyMap; import static java.util.Objects.nonNull; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -17,6 +18,7 @@ import com.google.common.primitives.Floats; import com.google.common.primitives.Ints; import java.util.Map; +import java.util.Objects; import java.util.stream.Stream; import lombok.Getter; import lombok.Setter; @@ -109,12 +111,23 @@ public class EvaluationContext { @Getter @Setter private String groupName; + @Getter + private final String uniqueId; public EvaluationContext(String testName, long startTimeNs) { - this(testName, startTimeNs, false); + this(String.valueOf(nanoTime()), testName, startTimeNs); } public EvaluationContext(String testName, long startTimeNs, boolean isAsyncEvaluation) { + this(String.valueOf(nanoTime()), testName, startTimeNs, isAsyncEvaluation); + } + + public EvaluationContext(String uniqueId, String testName, long startTimeNs) { + this(uniqueId, testName, startTimeNs, false); + } + + public EvaluationContext(String uniqueId, String testName, long startTimeNs, boolean isAsyncEvaluation) { + this.uniqueId = testName + "_" + uniqueId; this.testName = testName; this.startTimeNs = startTimeNs; this.startTime = DatetimeUtils.now(); @@ -180,6 +193,19 @@ public void runValidation() { noLatencyPercentileFailures(); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EvaluationContext context = (EvaluationContext) o; + return Objects.equals(testName, context.testName) && Objects.equals(groupName, context.groupName) && Objects.equals(uniqueId, context.uniqueId); + } + + @Override + public int hashCode() { + return Objects.hash(testName, groupName, uniqueId); + } + private boolean validateLatency(float actualMs, float requiredMs) { return requiredMs < 0 || actualMs <= requiredMs; } diff --git a/junitperf-core/src/main/java/com/github/noconnor/junitperf/reporting/providers/utils/ViewData.java b/junitperf-core/src/main/java/com/github/noconnor/junitperf/reporting/providers/utils/ViewData.java index 8c10ea7..3bd1a70 100644 --- a/junitperf-core/src/main/java/com/github/noconnor/junitperf/reporting/providers/utils/ViewData.java +++ b/junitperf-core/src/main/java/com/github/noconnor/junitperf/reporting/providers/utils/ViewData.java @@ -33,6 +33,7 @@ public static final class RequiredPercentilesData { } private final String testName; + private final String uniqueId; private final String testNameColour; private final String chartData; private final String csvData; @@ -62,6 +63,7 @@ public static final class RequiredPercentilesData { public ViewData(EvaluationContext context) { this.testName = buildTestName(context); + this.uniqueId = context.getUniqueId(); this.testNameColour = context.isAborted() ? SKIPPED_COLOUR : context.isSuccessful() ? SUCCESS_COLOUR : FAILED_COLOUR; this.chartData = buildChartData(context); this.csvData = buildCsvData(context); diff --git a/junitperf-core/src/main/resources/templates/report.template b/junitperf-core/src/main/resources/templates/report.template index ff3c815..235020a 100644 --- a/junitperf-core/src/main/resources/templates/report.template +++ b/junitperf-core/src/main/resources/templates/report.template @@ -14,7 +14,7 @@ - + @@ -22,7 +22,7 @@ - + {% END %} @@ -33,7 +33,7 @@ {% DETAILED_BLOCK %} -

{{ context.testName }}

+

{{ context.testName }}

   TestsTest
 {{ context.testName }}{{ context.testName }}
@@ -68,7 +68,7 @@ dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('{{ context.testName }}')); + var chart = new google.visualization.ScatterChart(document.getElementById('{{ context.uniqueId }}')); chart.draw(data, options); } @@ -80,15 +80,15 @@ ]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-{{ context.testName }}') + var link = document.getElementById('Export-{{ context.uniqueId }}') link.href=encodedUri; - link.download = '{{ context.testName }}.csv'; + link.download = '{{ context.uniqueId }}.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
diff --git a/junitperf-core/src/test/java/com/github/noconnor/junitperf/data/EvaluationContextTest.java b/junitperf-core/src/test/java/com/github/noconnor/junitperf/data/EvaluationContextTest.java index e36df09..864a3aa 100644 --- a/junitperf-core/src/test/java/com/github/noconnor/junitperf/data/EvaluationContextTest.java +++ b/junitperf-core/src/test/java/com/github/noconnor/junitperf/data/EvaluationContextTest.java @@ -66,6 +66,12 @@ public void tearDown(){ System.clearProperty(JUNITPERF_TOTAL_EXECUTIONS); } + @Test + public void whenANewContextIsCreated_thenAUniqueIdShouldBeAssignedToTheContext() { + int expected = String.valueOf(nanoTime()).length(); + assertTrue(context.getUniqueId().matches("UNITTEST_[\\d]{"+expected+"}")); + } + @Test public void whenLoadingJUnitPerfTestSettings_thenAppropriateContextSettingsShouldBeUpdated() { context.loadConfiguration(perfTestAnnotation); diff --git a/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/BaseReportGeneratorTest.java b/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/BaseReportGeneratorTest.java index 3fc3d82..d529b9f 100644 --- a/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/BaseReportGeneratorTest.java +++ b/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/BaseReportGeneratorTest.java @@ -7,6 +7,7 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.LinkedHashSet; @@ -52,7 +53,7 @@ protected File getResourceFile(String fileName) { } protected String readFileContents(final File file) throws IOException { - return new String(Files.readAllBytes(file.toPath()), Charset.forName("utf-8")).replaceAll("\\s+", ""); + return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).replaceAll("\\s+", ""); } protected void verifyAllValidationFailed(EvaluationContext context) { @@ -70,7 +71,7 @@ protected void verifyAllValidationPassed(EvaluationContext context) { } protected EvaluationContext createdFailedEvaluationContext(String name) { - EvaluationContext context = new EvaluationContext(name, nanoTime()); + EvaluationContext context = new EvaluationContext("unique_id", name, nanoTime()); context.setFinishTimeNs(nanoTime() + SECONDS.toNanos(10)); context.loadConfiguration(perfTestAnnotationMock); context.loadRequirements(perfTestRequirementAnnotationMock); @@ -80,7 +81,7 @@ protected EvaluationContext createdFailedEvaluationContext(String name) { } protected EvaluationContext createdSuccessfulEvaluationContext(String name) { - EvaluationContext context = new EvaluationContext(name, nanoTime()); + EvaluationContext context = new EvaluationContext("unique_id", name, nanoTime()); context.setFinishTimeNs(nanoTime() + SECONDS.toNanos(10)); context.loadConfiguration(perfTestAnnotationMock); context.loadRequirements(perfTestRequirementAnnotationMock); @@ -90,7 +91,7 @@ protected EvaluationContext createdSuccessfulEvaluationContext(String name) { } protected EvaluationContext createdAbortedEvaluationContext(String name) { - EvaluationContext context = new EvaluationContext(name, nanoTime()); + EvaluationContext context = new EvaluationContext("unique_id", name, nanoTime()); context.loadConfiguration(perfTestAnnotationMock); context.loadRequirements(perfTestRequirementAnnotationMock); context.setStatistics(createAbortedMock()); @@ -99,7 +100,7 @@ protected EvaluationContext createdAbortedEvaluationContext(String name) { } protected EvaluationContext createdSomeFailuresEvaluationContext(String name) { - EvaluationContext context = new EvaluationContext(name, nanoTime()); + EvaluationContext context = new EvaluationContext("unique_id", name, nanoTime()); context.setFinishTimeNs(nanoTime() + SECONDS.toNanos(10)); context.loadConfiguration(perfTestAnnotationMock); context.loadRequirements(perfTestRequirementAnnotationMock); diff --git a/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/providers/CsvReportGeneratorTest.java b/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/providers/CsvReportGeneratorTest.java index e29fc61..6bd8cd7 100644 --- a/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/providers/CsvReportGeneratorTest.java +++ b/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/providers/CsvReportGeneratorTest.java @@ -71,6 +71,14 @@ public void whenGeneratingAReport_andTestsContainsSomeAbortsAndFailures_thenAppr assertEquals(readFileContents(expectedContents), readFileContents(reportFile)); } + @Test + public void whenGeneratingAReport_andTestsContainsSomeAbortsAndFailures_andGenerateReportIsCalledMultipleTimes_thenAppropriateReportShouldBeGenerated() throws IOException { + reportGenerator.generateReport(generateAbortedFailedAndSuccessContexts()); + reportGenerator.generateReport(generateAbortedFailedAndSuccessContexts()); + File expectedContents = getResourceFile("csv/fail_abort_succeed.csv"); + assertEquals(readFileContents(expectedContents), readFileContents(reportFile)); + } + @Test public void whenCallingGetReportPath_andCustomPathHasBeenSpecified_thenCorrectPathShouldBeReturned() { assertThat(reportGenerator.getReportPath(), is(reportFile.getPath())); diff --git a/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/providers/HtmlReportGeneratorTest.java b/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/providers/HtmlReportGeneratorTest.java index f5e348d..edef7fe 100644 --- a/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/providers/HtmlReportGeneratorTest.java +++ b/junitperf-core/src/test/java/com/github/noconnor/junitperf/reporting/providers/HtmlReportGeneratorTest.java @@ -74,6 +74,14 @@ public void whenGeneratingAReport_andTestsContainsSomeAbortsAndFailures_thenAppr assertEquals(readFileContents(expectedContents), readFileContents(reportFile)); } + @Test + public void whenGeneratingAReport_andTestsContainsSomeAbortsAndFailures_andGenerateIsCalledMultipleTimes_thenAppropriateReportShouldBeGenerated() throws IOException { + reportGenerator.generateReport(generateAbortedFailedAndSuccessContexts()); + reportGenerator.generateReport(generateAbortedFailedAndSuccessContexts()); + File expectedContents = getResourceFile("html/example_aborted_failed_success.html"); + assertEquals(readFileContents(expectedContents), readFileContents(reportFile)); + } + @Test public void whenCallingGetReportPath_andCustomPathHasBeenSpecified_thenCorrectPathShouldBeReturned() { assertThat(reportGenerator.getReportPath(), is(reportFile.getPath())); @@ -101,7 +109,7 @@ public void whenHtmlProcessorProcessBlocksIsCalled_thenTheCorrectBlocksShouldBeP assertTrue(blocks.containsKey("{% DETAILED_BLOCK %}")); assertTrue(blocks.containsKey("{% PERCENTILES_BLOCK %}")); - assertEquals(919, blocks.get("root").length()); + assertEquals(918, blocks.get("root").length()); assertEquals(296, blocks.get("{% OVERVIEW_BLOCK %}").length()); assertEquals(7883, blocks.get("{% DETAILED_BLOCK %}").length()); assertEquals(704, blocks.get("{% PERCENTILES_BLOCK %}").length()); diff --git a/junitperf-core/src/test/resources/html/example_aborted_failed_success.html b/junitperf-core/src/test/resources/html/example_aborted_failed_success.html index f21ee48..043c1ae 100644 --- a/junitperf-core/src/test/resources/html/example_aborted_failed_success.html +++ b/junitperf-core/src/test/resources/html/example_aborted_failed_success.html @@ -14,28 +14,28 @@

JUnit Performance Report

- + - + - + - + @@ -46,7 +46,7 @@

JUnit Performance Report

-

unittest1

+

unittest1

   TestsTest
 unittest1unittest1
 unittest2 (skipped)unittest2 (skipped)
 unittest3unittest3
@@ -179,7 +179,7 @@

JUnit Performance Report

dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('unittest1')); + var chart = new google.visualization.ScatterChart(document.getElementById('unittest1_unique_id')); chart.draw(data, options); } @@ -290,15 +290,15 @@

JUnit Performance Report

]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-unittest1') + var link = document.getElementById('Export-unittest1_unique_id') link.href=encodedUri; - link.download = 'unittest1.csv'; + link.download = 'unittest1_unique_id.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
@@ -408,7 +408,7 @@

JUnit Performance Report




-

unittest3

+

unittest3

@@ -541,7 +541,7 @@

JUnit Performance Report

dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('unittest3')); + var chart = new google.visualization.ScatterChart(document.getElementById('unittest3_unique_id')); chart.draw(data, options); } @@ -652,15 +652,15 @@

JUnit Performance Report

]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-unittest3') + var link = document.getElementById('Export-unittest3_unique_id') link.href=encodedUri; - link.download = 'unittest3.csv'; + link.download = 'unittest3_unique_id.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
diff --git a/junitperf-core/src/test/resources/html/example_all_failed_report.html b/junitperf-core/src/test/resources/html/example_all_failed_report.html index 7f09e6f..940345b 100644 --- a/junitperf-core/src/test/resources/html/example_all_failed_report.html +++ b/junitperf-core/src/test/resources/html/example_all_failed_report.html @@ -14,20 +14,20 @@

JUnit Performance Report

- + - + - +
   TestsTest
 unittest1unittest1
 unittest2unittest2
@@ -36,7 +36,7 @@

JUnit Performance Report

-

unittest1

+

unittest1

@@ -269,7 +269,7 @@

JUnit Performance Report

dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('unittest1')); + var chart = new google.visualization.ScatterChart(document.getElementById('unittest1_unique_id')); chart.draw(data, options); } @@ -481,15 +481,15 @@

JUnit Performance Report

]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-unittest1') + var link = document.getElementById('Export-unittest1_unique_id') link.href=encodedUri; - link.download = 'unittest1.csv'; + link.download = 'unittest1_unique_id.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
@@ -597,7 +597,7 @@

JUnit Performance Report





-

unittest2

+

unittest2

@@ -830,7 +830,7 @@

JUnit Performance Report

dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('unittest2')); + var chart = new google.visualization.ScatterChart(document.getElementById('unittest2_unique_id')); chart.draw(data, options); } @@ -1042,15 +1042,15 @@

JUnit Performance Report

]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-unittest2') + var link = document.getElementById('Export-unittest2_unique_id') link.href=encodedUri; - link.download = 'unittest2.csv'; + link.download = 'unittest2_unique_id.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
diff --git a/junitperf-core/src/test/resources/html/example_all_passed_report.html b/junitperf-core/src/test/resources/html/example_all_passed_report.html index 18172fb..5cb3c07 100644 --- a/junitperf-core/src/test/resources/html/example_all_passed_report.html +++ b/junitperf-core/src/test/resources/html/example_all_passed_report.html @@ -14,20 +14,20 @@

JUnit Performance Report

- + - + - +
   TestsTest
 unittest1unittest1
 unittest2unittest2
@@ -36,7 +36,7 @@

JUnit Performance Report

-

unittest1

+

unittest1

@@ -269,7 +269,7 @@

JUnit Performance Report

dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('unittest1')); + var chart = new google.visualization.ScatterChart(document.getElementById('unittest1_unique_id')); chart.draw(data, options); } @@ -481,15 +481,15 @@

JUnit Performance Report

]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-unittest1') + var link = document.getElementById('Export-unittest1_unique_id') link.href=encodedUri; - link.download = 'unittest1.csv'; + link.download = 'unittest1_unique_id.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
@@ -597,7 +597,7 @@

JUnit Performance Report





-

unittest2

+

unittest2

@@ -830,7 +830,7 @@

JUnit Performance Report

dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('unittest2')); + var chart = new google.visualization.ScatterChart(document.getElementById('unittest2_unique_id')); chart.draw(data, options); } @@ -1042,15 +1042,15 @@

JUnit Performance Report

]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-unittest2') + var link = document.getElementById('Export-unittest2_unique_id') link.href=encodedUri; - link.download = 'unittest2.csv'; + link.download = 'unittest2_unique_id.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
diff --git a/junitperf-core/src/test/resources/html/example_mixed_report.html b/junitperf-core/src/test/resources/html/example_mixed_report.html index 30a9993..f7e312d 100644 --- a/junitperf-core/src/test/resources/html/example_mixed_report.html +++ b/junitperf-core/src/test/resources/html/example_mixed_report.html @@ -14,20 +14,20 @@

JUnit Performance Report

- + - + - +
   TestsTest
 unittest1unittest1
 unittest2unittest2
@@ -36,7 +36,7 @@

JUnit Performance Report

-

unittest1

+

unittest1

@@ -269,7 +269,7 @@

JUnit Performance Report

dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('unittest1')); + var chart = new google.visualization.ScatterChart(document.getElementById('unittest1_unique_id')); chart.draw(data, options); } @@ -481,15 +481,15 @@

JUnit Performance Report

]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-unittest1') + var link = document.getElementById('Export-unittest1_unique_id') link.href=encodedUri; - link.download = 'unittest1.csv'; + link.download = 'unittest1_unique_id.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
@@ -597,7 +597,7 @@

JUnit Performance Report





-

unittest2

+

unittest2

@@ -830,7 +830,7 @@

JUnit Performance Report

dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('unittest2')); + var chart = new google.visualization.ScatterChart(document.getElementById('unittest2_unique_id')); chart.draw(data, options); } @@ -1042,15 +1042,15 @@

JUnit Performance Report

]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-unittest2') + var link = document.getElementById('Export-unittest2_unique_id') link.href=encodedUri; - link.download = 'unittest2.csv'; + link.download = 'unittest2_unique_id.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
diff --git a/junitperf-core/src/test/resources/html/example_some_failures_report.html b/junitperf-core/src/test/resources/html/example_some_failures_report.html index 0add4de..9e64919 100644 --- a/junitperf-core/src/test/resources/html/example_some_failures_report.html +++ b/junitperf-core/src/test/resources/html/example_some_failures_report.html @@ -14,14 +14,14 @@

JUnit Performance Report

- + - +
   TestsTest
 unittest1unittest1
@@ -30,7 +30,7 @@

JUnit Performance Report

-

unittest1

+

unittest1

@@ -263,7 +263,7 @@

JUnit Performance Report

dataOpacity: 0.5 }; - var chart = new google.visualization.ScatterChart(document.getElementById('unittest1')); + var chart = new google.visualization.ScatterChart(document.getElementById('unittest1_unique_id')); chart.draw(data, options); } @@ -475,15 +475,15 @@

JUnit Performance Report

]); var csvFormattedDataTable = google.visualization.dataTableToCsv(csvData); var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable); - var link = document.getElementById('Export-unittest1') + var link = document.getElementById('Export-unittest1_unique_id') link.href=encodedUri; - link.download = 'unittest1.csv'; + link.download = 'unittest1_unique_id.csv'; link.target = '_blank'; } -
- Download as csv +
+ Download as csv
diff --git a/junitperf-junit5/src/main/java/com/github/noconnor/junitperf/JUnitPerfInterceptor.java b/junitperf-junit5/src/main/java/com/github/noconnor/junitperf/JUnitPerfInterceptor.java index de81726..9a28bee 100644 --- a/junitperf-junit5/src/main/java/com/github/noconnor/junitperf/JUnitPerfInterceptor.java +++ b/junitperf-junit5/src/main/java/com/github/noconnor/junitperf/JUnitPerfInterceptor.java @@ -12,6 +12,7 @@ import com.github.noconnor.junitperf.suite.SuiteRegistry; import com.github.noconnor.junitperf.utils.TestReflectionUtils; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.InvocationInterceptor; @@ -50,8 +51,11 @@ public class JUnitPerfInterceptor implements InvocationInterceptor, TestInstance } @Data + @EqualsAndHashCode(onlyExplicitlyIncluded = true) protected static class TestDetails { + @EqualsAndHashCode.Include private Class testClass; + @EqualsAndHashCode.Include private Method testMethod; private long measurementsStartTimeMs; private EvaluationContext context; @@ -98,7 +102,8 @@ public void interceptTestMethod(Invocation invocation, JUnitPerfTestRequirement requirementsAnnotation = getJUnitPerfTestRequirementDetails(method, extensionContext); if (nonNull(perfTestAnnotation)) { - + log.trace("Using {} for {} : {}", perfTestAnnotation, getUniqueId(extensionContext), getUniqueId(extensionContext.getRoot())); + boolean isAsync = invocationContext.getArguments().stream().anyMatch(arg -> arg instanceof TestContextSupplier); EvaluationContext context = createEvaluationContext(method, isAsync); context.loadConfiguration(perfTestAnnotation); @@ -123,14 +128,16 @@ public void interceptTestMethod(Invocation invocation, parallelExecution.runParallelEvaluation(); - proceedQuietly(invocation); + // Must be called for framework to proceed + invocation.skip(); } else { + log.trace("No @JUnitPerfTest annotation for {} : {}", getUniqueId(extensionContext), getUniqueId(extensionContext.getRoot())); invocation.proceed(); } } - + @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { return parameterContext.getParameter().getType() == TestContextSupplier.class; @@ -162,7 +169,7 @@ protected JUnitPerfTest getJUnitPerfTestDetails(Method method, ExtensionContext protected EvaluationContext createEvaluationContext(Method method, boolean isAsync) { EvaluationContext ctx = new EvaluationContext(method.getName(), nanoTime(), isAsync); - ctx.setGroupName(method.getDeclaringClass().getSimpleName()); + ctx.setGroupName(method.getDeclaringClass().getName()); return ctx; } @@ -201,13 +208,8 @@ private static JUnitPerfReportingConfig scanForReportingConfig(Object testInstan return scanForReportingConfig(testInstance, testClass.getSuperclass()); } - private static void proceedQuietly(Invocation invocation) throws Throwable { - try { - // Must be called for framework to proceed - invocation.proceed(); - } catch (Throwable e) { - log.trace("Proceed error", e); - } + private static String getUniqueId(ExtensionContext extensionContext) { + return nonNull(extensionContext) ? extensionContext.getUniqueId() : "(no root)"; } private static TestDetails getTestDetails(ExtensionContext extensionContext) { diff --git a/junitperf-junit5/src/test/java/com/github/noconnor/junitperf/JUnitPerfInterceptorTest.java b/junitperf-junit5/src/test/java/com/github/noconnor/junitperf/JUnitPerfInterceptorTest.java index 3bc9a2a..bc4039f 100644 --- a/junitperf-junit5/src/test/java/com/github/noconnor/junitperf/JUnitPerfInterceptorTest.java +++ b/junitperf-junit5/src/test/java/com/github/noconnor/junitperf/JUnitPerfInterceptorTest.java @@ -13,8 +13,6 @@ import com.github.noconnor.junitperf.statistics.StatisticsCalculator; import com.github.noconnor.junitperf.statistics.providers.DescriptiveStatisticsCalculator; import com.github.noconnor.junitperf.suite.SuiteRegistry; -import org.junit.Assert; -import org.junit.AssumptionViolatedException; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -204,9 +202,9 @@ void whenTestHasBeenAnnotatedWithPerfAnnotations_thenTestStatementShouldBeBuilt( // Override statement builder getSharedContext(extensionContextMock).setStatementBuilder(() -> statementBuilderMock); interceptor.interceptTestMethod(invocationMock, invocationContextMock, extensionContextMock); - - verify(invocationMock).proceed(); + verify(statementMock).runParallelEvaluation(); + verify(invocationMock).skip(); assertNotNull(getTestContext(extensionContextMock)); EvaluationContext context = captureEvaluationContext();