Skip to content

Commit

Permalink
#57: a first simple implementation of color printed console reporting.
Browse files Browse the repository at this point in the history
will be further polished and tested
  • Loading branch information
Matthias Merdes authored and Matthias Merdes committed Jan 21, 2016
1 parent 15e458e commit 338d1e4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ public LocalDateTime getCreationTimestamp() {
return creationTimestamp;
}

@Override
public String toString() {
//migrate to org.junit.gen5.commons.util.ToStringBuilder?
return this.values.toString() + " @ " + this.creationTimestamp;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.PrintWriter;

import org.junit.gen5.commons.reporting.ReportEntry;
import org.junit.gen5.engine.TestExecutionResult;
import org.junit.gen5.engine.TestExecutionResult.Status;
import org.junit.gen5.launcher.TestExecutionListener;
Expand Down Expand Up @@ -67,6 +68,12 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
testExecutionResult.getThrowable().ifPresent(t -> printlnException(color, t));
}

@Override
public void reportingEntryPublished(TestIdentifier testIdentifier, ReportEntry entry) {
printlnTestDescriptor(PURPLE, "Reported:", testIdentifier);
printlnMessage(PURPLE, "Reported values", entry.toString());
}

private Color determineColor(Status status) {
switch (status) {
case SUCCESSFUL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.function.Consumer;

import org.junit.gen5.commons.reporting.ReportEntry;
import org.junit.gen5.engine.TestExecutionResult;
import org.junit.gen5.launcher.TestExecutionListener;
import org.junit.gen5.launcher.TestIdentifier;
Expand Down Expand Up @@ -71,6 +72,12 @@ public void testPlanExecutionStarted(TestPlan testPlan) {
public void testPlanExecutionFinished(TestPlan testPlan) {
notifyTestExecutionListeners(listener -> listener.testPlanExecutionFinished(testPlan));
}

@Override
public void reportingEntryPublished(TestIdentifier testIdentifier, ReportEntry entry) {
notifyTestExecutionListeners(listener -> listener.reportingEntryPublished(testIdentifier, entry));
}

}

}
6 changes: 6 additions & 0 deletions junit5-api/src/main/java/org/junit/gen5/api/TestReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

package org.junit.gen5.api;

import java.util.Map;

import org.junit.gen5.commons.reporting.ReportEntry;

/**
Expand Down Expand Up @@ -37,4 +39,8 @@ default void publishEntry(String key, String value) {
this.publishEntry(ReportEntry.from(key, value));
}

default void publishEntry(Map<String, String> values) {
this.publishEntry(ReportEntry.from(values));
}

}
3 changes: 2 additions & 1 deletion sample-project/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ task runSampleTestCases(type: JavaExec) {
// args '-h'
// args 'com.example'
// args '--all', '-n', '.*TestCase', '-t', 'fast'
args '--all', '--hide-details'
// args '--all', '--hide-details'
args '--all'
}

test {
Expand Down
31 changes: 31 additions & 0 deletions sample-project/src/test/java/com/example/ReportingTestCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2015-2016 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/

package com.example;

import java.util.HashMap;

import org.junit.gen5.api.Test;
import org.junit.gen5.api.TestReporter;

public class ReportingTestCase {

@Test
void testWithReporting(TestReporter testReporter) {

HashMap<String, String> values = new HashMap<>();
values.put("user name", "dk38");
values.put("award year", "1974");

testReporter.publishEntry(values);

}

}

0 comments on commit 338d1e4

Please sign in to comment.