Skip to content

Commit

Permalink
Fix for suite of suites (#104)
Browse files Browse the repository at this point in the history
* Fix for suite of suites

* Fixing incorrect comment

---------

Co-authored-by: noconnor <[email protected]>
  • Loading branch information
noconnor and noconnor authored Jun 26, 2023
1 parent b99b83f commit 67ff29f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
public class SuiteRegistry {

private static final Map<String, SuiteSettings> settingsCache = new HashMap<>();
private static final Pattern suiteClassPattern = Pattern.compile(".*\\[suite:([^\\]]*)\\].*");
private static final Pattern suiteClassPattern = Pattern.compile("\\[suite:([^\\]]*)\\]");

public static void scanForSuiteDetails(ExtensionContext context) {

String rootUniqueId = getRootId(context);
Class<?> clazz = getSuiteClass(rootUniqueId);
Class<?> clazz = getTopLevelSuiteClass(rootUniqueId);

if (isNull(clazz) || settingsCache.containsKey(rootUniqueId)) {
return;
Expand Down Expand Up @@ -82,9 +82,9 @@ private static String getRootId(ExtensionContext context) {
return "";
}

private static Class<?> getSuiteClass(String rootUniqueId) {
private static Class<?> getTopLevelSuiteClass(String rootUniqueId) {
Matcher m = suiteClassPattern.matcher(rootUniqueId);
if (m.find()) {
if (m.find()) { // find first match - root suite
try {
return Class.forName(m.group(1));
} catch (ClassNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -110,6 +112,21 @@ void whenTestSuiteClassIsConfigured_andSuiteHasBadReporterConfig_thenSuitePerfDa
assertEquals(0.168F, requirements.allowedErrorPercentage());
}

@Test
void whenTestSuiteIsASuiteOfSuites_andTopLevelSuiteHasPerfAnnotation_thenSuitePerfDataShouldBeAvailable() {
ExtensionContext context = createMockExtensionContext(buildSuiteOfSuitesId(DummySuiteOfSuites.class, DummySuite.class));
SuiteRegistry.scanForSuiteDetails(context);
JUnitPerfTest testSpec = SuiteRegistry.getPerfTestData(context);
JUnitPerfTestRequirement requirements = SuiteRegistry.getPerfRequirements(context);

assertNotNull(testSpec);
assertNotNull(requirements);
assertNotNull(SuiteRegistry.getReportingConfig(context));

assertEquals(0.198F, requirements.allowedErrorPercentage());
assertEquals(376, testSpec.totalExecutions());
}

private static String buildSuiteId(Class<?> clazz) {
return buildSuiteId(clazz.getName());
}
Expand All @@ -118,6 +135,14 @@ private static String buildSuiteId(String clazz) {
return "[engine:junit-platform-suite]/[suite:" + clazz + "]/[engine:junit-jupiter]";
}

private static String buildSuiteOfSuitesId(Class<?> clazz1, Class<?> clazz2) {
return buildSuiteOfSuitesId(clazz1.getName(), clazz2.getName());
}

private static String buildSuiteOfSuitesId(String suiteClazz1, String suiteClazz2) {
return "[engine:junit-platform-suite]/[suite:" + suiteClazz1 + "]/[engine:junit-platform-suite]/[suite:" + suiteClazz2 + "]/[engine:junit-jupiter]";
}

private static ExtensionContext createMockExtensionContext(String rootId) {
ExtensionContext childContext = mock(ExtensionContext.class);
ExtensionContext rootContext = mock(ExtensionContext.class);
Expand Down Expand Up @@ -162,4 +187,29 @@ public static class DummySuiteBadReporterConfigs {
@JUnitPerfTestActiveConfig // not static - should be dropped
public JUnitPerfReportingConfig config = JUnitPerfReportingConfig.builder().build();
}

@Disabled
@Suite
@SelectClasses(DummySuite.class)
@JUnitPerfTest(totalExecutions = 376)
@JUnitPerfTestRequirement(allowedErrorPercentage = 0.198F)
public static class DummySuiteOfSuites {
@JUnitPerfTestActiveConfig
public static JUnitPerfReportingConfig config = JUnitPerfReportingConfig.builder().build();
}

@Disabled
@Suite
@SelectClasses(DummyTestClass.class)
public static class DummySuite {
}

@Disabled
public static class DummyTestClass {

@Test
void someTest() {
assertTrue(true);
}
}
}

0 comments on commit 67ff29f

Please sign in to comment.