Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Junit windows fix #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Date;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.lang.System;

/**
* Actions to run tests (usually acceptance tests).
Expand All @@ -26,6 +27,9 @@ public class JUnitActions {
public static final String JUNIT_REPORT_FOLDER = ".junit-reports";
public static final String JUPITER_REPORT_NAME = "TEST-junit-jupiter.xml";
public static final String VINTAGE_REPORT_NAME = "TEST-junit-vintage.xml";

private static boolean isWindows = false;
private static boolean osChecked = false;

public static final DateFormat FOLDERNAME_FROM_TIMESTAMP_FORMAT = new java.text.SimpleDateFormat("yyyy-MM-dd--HH-mm-ss--SSS");

Expand All @@ -51,7 +55,11 @@ public static TestResults test (File junitRunner, String testClass, String class
result = OS.exe(new File("."), "java","-jar", junitRunner.getAbsolutePath(), "-reports-dir",junitReportFolder.getAbsolutePath(),"-c",testClass);
}
else {
result = OS.exe(new File("."), "java","-jar", junitRunner.getAbsolutePath(), "-reports-dir",junitReportFolder.getAbsolutePath(),"-cp",classpath,"-c",testClass);
if (checkOSisWindows()) {
result = adjustRunnerForWindows(classpath, junitRunner, junitReportFolder, testClass);
} else {
result = OS.exe(new File("."), "java","-jar", junitRunner.getAbsolutePath(), "-reports-dir",junitReportFolder.getAbsolutePath(),"-cp",classpath,"-c",testClass);
}
}

// parse results
Expand Down Expand Up @@ -105,6 +113,38 @@ private static void extractStatsFromReport(File junitReport, TestResults testRes
int testResultingInErrorCounts = XML.evalXPathSingleNodeAsInt(junitReport, "/testsuite/@errors");
testResults.addToTestsWithErrors(testResultingInErrorCounts);
}

private static ProcessResult adjustRunnerForWindows(String classpath, File junitRunner, File junitReportFolder, String testClass) throws Exception {
//Prepend junit jar to classpath
classpath = junitRunner.getAbsolutePath()+File.pathSeparator+classpath;

//Extract spring-mock dependency from classpath, and append to end
String[] cp = classpath.split(File.pathSeparator);
String cp2 = "";
String mock = "";
for (int i = 0; i < cp.length; i++) {
if (!cp[i].contains("spring-mock")) {
cp2 += cp[i] + File.pathSeparator;
} else {
mock = cp[i];
}
}
cp2 += File.pathSeparator+mock;

//Execute jar from classpath
return OS.exe(new File("."), "java","-cp", cp2, "org.junit.platform.console.ConsoleLauncher", "-reports-dir",junitReportFolder.getAbsolutePath(),"-c",testClass);
}

private static boolean checkOSisWindows() {
if (!osChecked) {
if (System.getProperty("os.name").toLowerCase().contains("win")) {
isWindows = true;
}
osChecked = true;
}

return isWindows;
}


}