Skip to content

Commit

Permalink
Fix suite name calculation for jqwuik framework (#6108)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog authored Oct 30, 2023
1 parent d6fbe39 commit eeb3363
Showing 1 changed file with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,31 @@ private void testCaseExecutionStarted(final TestDescriptor testDescriptor) {
}

private void testMethodExecutionStarted(TestDescriptor testDescriptor, MethodSource testSource) {
String testSuitName = testSource.getClassName();
TestDescriptor suiteDescriptor = getSuiteDescriptor(testDescriptor);

Class<?> testClass;
String testSuiteName;
if (suiteDescriptor != null) {
testClass = JUnitPlatformUtils.getJavaClass(suiteDescriptor);
testSuiteName =
testClass != null ? testClass.getName() : suiteDescriptor.getLegacyReportingName();
} else {
testClass = JUnitPlatformUtils.getTestClass(testSource);
testSuiteName = testSource.getClassName();
}

String displayName = testDescriptor.getDisplayName();
String testName = testSource.getMethodName();

String testParameters = JUnitPlatformUtils.getParameters(testSource, displayName);
List<String> tags =
testDescriptor.getTags().stream().map(TestTag::getName).collect(Collectors.toList());

Class<?> testClass = JUnitPlatformUtils.getTestClass(testSource);
Method testMethod = JUnitPlatformUtils.getTestMethod(testSource);
String testMethodName = testSource.getMethodName();

TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestStart(
testSuitName,
testSuiteName,
testName,
null,
testFramework,
Expand All @@ -144,8 +155,19 @@ private static void testMethodExecutionFinished(
TestDescriptor testDescriptor,
TestExecutionResult testExecutionResult,
MethodSource testSource) {
String testSuiteName = testSource.getClassName();
Class<?> testClass = JUnitPlatformUtils.getTestClass(testSource);
TestDescriptor suiteDescriptor = getSuiteDescriptor(testDescriptor);

Class<?> testClass;
String testSuiteName;
if (suiteDescriptor != null) {
testClass = JUnitPlatformUtils.getJavaClass(suiteDescriptor);
testSuiteName =
testClass != null ? testClass.getName() : suiteDescriptor.getLegacyReportingName();
} else {
testClass = JUnitPlatformUtils.getTestClass(testSource);
testSuiteName = testSource.getClassName();
}

String displayName = testDescriptor.getDisplayName();
String testName = testSource.getMethodName();
String testParameters = JUnitPlatformUtils.getParameters(testSource, displayName);
Expand Down Expand Up @@ -203,18 +225,29 @@ private void containerExecutionSkipped(final TestDescriptor testDescriptor, fina
}

private void testMethodExecutionSkipped(
final TestDescriptor testDescriptor, final MethodSource methodSource, final String reason) {
String testSuiteName = methodSource.getClassName();
final TestDescriptor testDescriptor, final MethodSource testSource, final String reason) {
TestDescriptor suiteDescriptor = getSuiteDescriptor(testDescriptor);

Class<?> testClass;
String testSuiteName;
if (suiteDescriptor != null) {
testClass = JUnitPlatformUtils.getJavaClass(suiteDescriptor);
testSuiteName =
testClass != null ? testClass.getName() : suiteDescriptor.getLegacyReportingName();
} else {
testClass = JUnitPlatformUtils.getTestClass(testSource);
testSuiteName = testSource.getClassName();
}

String displayName = testDescriptor.getDisplayName();
String testName = methodSource.getMethodName();
String testName = testSource.getMethodName();

String testParameters = JUnitPlatformUtils.getParameters(methodSource, displayName);
String testParameters = JUnitPlatformUtils.getParameters(testSource, displayName);
List<String> tags =
testDescriptor.getTags().stream().map(TestTag::getName).collect(Collectors.toList());

Class<?> testClass = JUnitPlatformUtils.getTestClass(methodSource);
Method testMethod = JUnitPlatformUtils.getTestMethod(methodSource);
String testMethodName = methodSource.getMethodName();
Method testMethod = JUnitPlatformUtils.getTestMethod(testSource);
String testMethodName = testSource.getMethodName();

TestEventsHandlerHolder.TEST_EVENTS_HANDLER.onTestIgnore(
testSuiteName,
Expand All @@ -229,4 +262,11 @@ private void testMethodExecutionSkipped(
testMethod,
reason);
}

private static TestDescriptor getSuiteDescriptor(TestDescriptor testDescriptor) {
while (testDescriptor != null && !JUnitPlatformUtils.isSuite(testDescriptor)) {
testDescriptor = testDescriptor.getParent().orElse(null);
}
return testDescriptor;
}
}

0 comments on commit eeb3363

Please sign in to comment.