Skip to content

Commit

Permalink
test reporting tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaRB committed Dec 13, 2023
1 parent b888076 commit 4565c56
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/main/java/crml/compiler/TestListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.platform.launcher.TestIdentifier;
import org.junit.platform.launcher.TestPlan;

import com.aventstack.extentreports.AnalysisStrategy;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
Expand All @@ -22,17 +23,16 @@

public class TestListener implements TestExecutionListener {

private final ExtentSparkReporter reporter = new ExtentSparkReporter("build/test_report.html");
private final ExtentSparkReporter reporter = new ExtentSparkReporter("build"+ java.io.File.separator+ "test_report.html");
private final ExtentReports extentReport = new ExtentReports();
private static final Map<TestIdentifier, TestExecutionResult> RESULTS = new HashMap<>();
private static final Map<TestIdentifier, String> SKIPPED = new HashMap<>();

@Override
public void testPlanExecutionStarted(TestPlan testPlan) {
this.extentReport.attachReporter(reporter);
this.extentReport.setSystemInfo("strin 1", "string 2");
this.extentReport.setAnalysisStrategy(AnalysisStrategy.CLASS);
testPlan.getChildren(getRoot(testPlan)).forEach(testIdentifier -> {
System.out.printf("Adding parent [%s]%n", testIdentifier.getUniqueId());
RESULTS.put(testIdentifier, null);
});

Expand All @@ -43,7 +43,6 @@ public void testPlanExecutionFinished(TestPlan testPlan) {
testPlan.getChildren(getRoot(testPlan)).forEach(klass -> {
if (SKIPPED.containsKey(klass)) {
extentReport.createTest(getKlassName(klass.getUniqueId())).skip(SKIPPED.get(klass));
System.out.printf("Marking klass [%s] as skipped%n", klass.getDisplayName());
} else if (RESULTS.containsKey(klass)) {
final ExtentTest testKlass = extentReport.createTest(getKlassName(klass.getUniqueId()));
testPlan.getDescendants(klass).forEach(test -> processTestNode(testKlass, test));
Expand All @@ -59,18 +58,14 @@ private void processTestNode(ExtentTest testKlass, TestIdentifier test) {
}
if (SKIPPED.containsKey(test)) {
node.skip(SKIPPED.get(test));
System.out.printf("Marking test [%s] as skipped%n", test.getDisplayName());
return;
}
final TestExecutionResult testResult = RESULTS.get(test);
if (testResult == null) {
node.log(INFO, "No test results found");
return;
}

System.err.println("-------------" + (testResult.getStatus()==Status.SUCCESSFUL));



if(testResult.getStatus()==Status.SUCCESSFUL)
node.pass(testResult.toString());
else if(testResult.getStatus()==Status.ABORTED)
Expand Down

0 comments on commit 4565c56

Please sign in to comment.