Skip to content
Permalink
Browse files

normalize test listeners across junit4,5 and groovy cli (#457)

  • Loading branch information
MykolaGolubyev committed Nov 23, 2019
1 parent 6dc6f99 commit f269b62dad88a5b07c89a50d1ddb0bc8bb7b1e10
Showing with 433 additions and 582 deletions.
  1. +1 −0 webtau-browser/src/main/resources/META-INF/services/com.twosigma.webtau.reporter.StepReporter
  2. +40 −0 webtau-core/src/main/java/com/twosigma/webtau/reporter/ConsoleTestListener.java
  3. +15 −0 webtau-core/src/main/java/com/twosigma/webtau/reporter/TestListener.java
  4. +36 −0 webtau-core/src/main/java/com/twosigma/webtau/reporter/TestListeners.java
  5. +23 −0 webtau-core/src/main/java/com/twosigma/webtau/reporter/TestResultPayloadExtractorTestListener.java
  6. +0 −1 webtau-core/src/main/java/com/twosigma/webtau/reporter/TestResultPayloadExtractors.java
  7. +31 −43 ...ort/ReportSummary.java → webtau-core/src/main/java/com/twosigma/webtau/reporter/WebTauReport.java
  8. +4 −11 ...ort/ReportTestEntry.java → webtau-core/src/main/java/com/twosigma/webtau/reporter/WebTauTest.java
  9. +17 −19 ...portTestEntries.java → webtau-core/src/main/java/com/twosigma/webtau/reporter/WebTauTestList.java
  10. +1 −0 webtau-core/src/main/resources/META-INF/services/com.twosigma.webtau.reporter.TestListener
  11. +3 −3 webtau-feature-testing/examples/scenarios/rest/report/Report.groovy
  12. +8 −18 ...eature-testing/src/main/groovy/com/twosigma/webtau/featuretesting/WebTauEndToEndTestRunner.groovy
  13. +13 −16 webtau-groovy/src/main/groovy/com/twosigma/webtau/cli/CliReportGenerator.groovy
  14. +11 −45 webtau-groovy/src/main/groovy/com/twosigma/webtau/cli/WebTauCliApp.groovy
  15. +1 −1 webtau-groovy/src/main/groovy/com/twosigma/webtau/cli/interactive/InteractiveTests.groovy
  16. +4 −4 webtau-groovy/src/main/groovy/com/twosigma/webtau/cli/interactive/WebTauCliInteractive.groovy
  17. +3 −2 webtau-groovy/src/test/groovy/com/twosigma/webtau/cfg/WebTauGroovyFileConfigHandlerTest.groovy
  18. +5 −5 webtau-http/src/main/java/com/twosigma/webtau/http/report/HttpCallsReportDataProvider.java
  19. +8 −8 webtau-http/src/test/groovy/com/twosigma/webtau/http/report/HttpCallsReportDataProviderTest.groovy
  20. +8 −8 webtau-java-runner/src/main/java/com/twosigma/webtau/javarunner/report/JavaBasedTest.java
  21. +25 −7 webtau-java-runner/src/main/java/com/twosigma/webtau/javarunner/report/JavaReport.java
  22. +5 −6 .../java/com/twosigma/webtau/javarunner/report/{JavaReportShutdownHook.java → JavaShutdownHook.java}
  23. +19 −17 webtau-junit4/src/main/java/com/twosigma/webtau/junit4/WebTauRunner.java
  24. +36 −30 webtau-junit5/src/main/java/com/twosigma/webtau/junit5/WebTauJunitExtension.java
  25. +2 −2 webtau-open-api/src/main/java/com/twosigma/webtau/openapi/OpenApiReportDataProvider.java
  26. +22 −6 webtau-report/src/main/java/com/twosigma/webtau/report/HtmlReportGenerator.java
  27. +0 −63 webtau-report/src/main/java/com/twosigma/webtau/report/Report.java
  28. +3 −1 webtau-report/src/main/java/com/twosigma/webtau/report/ReportDataProvider.java
  29. +3 −3 webtau-report/src/main/java/com/twosigma/webtau/report/ReportDataProviders.java
  30. +3 −1 webtau-report/src/main/java/com/twosigma/webtau/report/ReportGenerator.java
  31. +2 −2 webtau-report/src/main/java/com/twosigma/webtau/report/ReportGenerators.java
  32. +29 −30 ...ndalone-runner-groovy/src/main/groovy/com/twosigma/webtau/runner/standalone/StandaloneTest.groovy
  33. +0 −27 ...runner-groovy/src/main/groovy/com/twosigma/webtau/runner/standalone/StandaloneTestListener.groovy
  34. +0 −41 ...groovy/src/main/groovy/com/twosigma/webtau/runner/standalone/StandaloneTestListenerAdapter.groovy
  35. +0 −54 ...unner-groovy/src/main/groovy/com/twosigma/webtau/runner/standalone/StandaloneTestListeners.groovy
  36. +36 −43 ...e-runner-groovy/src/main/groovy/com/twosigma/webtau/runner/standalone/StandaloneTestRunner.groovy
  37. +0 −49 ...y/src/main/groovy/com/twosigma/webtau/runner/standalone/report/StandardConsoleTestListener.groovy
  38. +3 −3 ...nner-groovy/src/test/groovy/com/twosigma/webtau/runner/standalone/StandaloneTestRunnerTest.groovy
  39. +13 −13 ...one-runner-groovy/src/test/groovy/com/twosigma/webtau/runner/standalone/StandaloneTestTest.groovy
@@ -0,0 +1 @@
com.twosigma.webtau.browser.reporter.ScreenshotStepReporter
@@ -0,0 +1,40 @@
package com.twosigma.webtau.reporter;

import com.twosigma.webtau.console.ConsoleOutputs;
import com.twosigma.webtau.console.ansi.Color;

public class ConsoleTestListener implements TestListener {
@Override
public void beforeFirstTest() {
}

@Override
public void afterAllTests(WebTauReport report) {
}

@Override
public void beforeTestRun(WebTauTest test) {
ConsoleOutputs.out(Color.BLUE, test.getScenario().trim(), " ",
Color.PURPLE, "(" + test.getShortContainerId() + ")");
}

@Override
public void afterTestRun(WebTauTest test) {
if (test.isFailed()) {
outAfter(Color.RED, "[x]", test);
} else if (test.hasError()) {
outAfter(Color.RED, "[~]", test);
} else if (test.isSkipped()) {
outAfter(Color.YELLOW, "[o]", test);
} else {
outAfter(Color.GREEN, "[.]", test);
}

ConsoleOutputs.out();
}

private static void outAfter(Color color, String icon, WebTauTest test) {
ConsoleOutputs.out(color, icon, ' ', Color.BLUE, test.getScenario().trim(),
' ', Color.PURPLE, '(' + test.getShortContainerId() + ')');
}
}
@@ -0,0 +1,15 @@
package com.twosigma.webtau.reporter;

/**
* Lowest common denominator for Groovy Standalone Tests, JUnit4, JUnit5, etc
* Core usage is to print current test name
*/
public interface TestListener {
void beforeFirstTest();

void beforeTestRun(WebTauTest test);

void afterTestRun(WebTauTest test);

void afterAllTests(WebTauReport report);
}
@@ -0,0 +1,36 @@
package com.twosigma.webtau.reporter;

import com.twosigma.webtau.utils.ServiceLoaderUtils;

import java.util.List;

public class TestListeners {
private static List<TestListener> listeners = ServiceLoaderUtils.load(TestListener.class);

private TestListeners() {
}

public static void beforeTestRun(WebTauTest test) {
listeners.forEach(listener -> listener.beforeTestRun(test));
}

public static void afterTestRun(WebTauTest test) {
listeners.forEach(listener -> listener.afterTestRun(test));
}

public static void beforeFirstTest() {
listeners.forEach(TestListener::beforeFirstTest);
}

public static void afterAllTests(WebTauReport report) {
listeners.forEach(listeners -> listeners.afterAllTests(report));
}

public static void add(TestListener listener) {
listeners.add(listener);
}

public static void remove(TestListener listener) {
listeners.remove(listener);
}
}
@@ -0,0 +1,23 @@
package com.twosigma.webtau.reporter;

/**
* Extracts {@link TestStep} payloads from all test steps at the end of the test and re-attaches it as a test payload.
*/
public class TestResultPayloadExtractorTestListener implements TestListener {
@Override
public void beforeFirstTest() {
}

@Override
public void beforeTestRun(WebTauTest test) {
}

@Override
public void afterTestRun(WebTauTest test) {
TestResultPayloadExtractors.extract(test.getSteps().stream()).forEach(test::addTestResultPayload);
}

@Override
public void afterAllTests(WebTauReport report) {
}
}
@@ -20,7 +20,6 @@

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@@ -14,34 +14,48 @@
* limitations under the License.
*/

package com.twosigma.webtau.report;
package com.twosigma.webtau.reporter;

import com.twosigma.webtau.reporter.TestStatus;

import java.util.LinkedHashMap;
import java.util.Map;
public class WebTauReport {
private final long startTime;
private final long stopTime;
private final WebTauTestList tests;

public class ReportSummary {
private final long total;
private final long passed;
private final long failed;
private final long skipped;
private final long errored;

private final long startTime;
private final long stopTime;
private final long duration;

ReportSummary(ReportTestEntries testEntries, long startTime, long stopTime) {
total = testEntries.size();
passed = testEntries.countWithStatus(TestStatus.Passed);
failed = testEntries.countWithStatus(TestStatus.Failed);
skipped = testEntries.countWithStatus(TestStatus.Skipped);
errored = testEntries.countWithStatus(TestStatus.Errored);

public WebTauReport(WebTauTestList tests, long startTime, long stopTime) {
this.startTime = startTime;
this.stopTime = stopTime;
this.duration = stopTime - startTime;
this.tests = tests;

duration = stopTime - startTime;

total = tests.size();
passed = tests.countWithStatus(TestStatus.Passed);
failed = tests.countWithStatus(TestStatus.Failed);
skipped = tests.countWithStatus(TestStatus.Skipped);
errored = tests.countWithStatus(TestStatus.Errored);
}

public WebTauTestList getTests() {
return tests;
}

public long getStartTime() {
return startTime;
}

public long getStopTime() {
return stopTime;
}

public long getDuration() {
return duration;
}

public long getTotal() {
@@ -63,30 +77,4 @@ public long getSkipped() {
public long getErrored() {
return errored;
}

public long getStartTime() {
return startTime;
}

public long getStopTime() {
return stopTime;
}

public long getDuration() {
return duration;
}

public Map<String, ?> toMap() {
Map<String, Object> result = new LinkedHashMap<>();
result.put("total", total);
result.put("passed", passed);
result.put("failed", failed);
result.put("skipped", skipped);
result.put("errored", errored);
result.put("startTime", startTime);
result.put("stopTime", stopTime);
result.put("duration", duration);

return result;
}
}
@@ -14,11 +14,8 @@
* limitations under the License.
*/

package com.twosigma.webtau.report;
package com.twosigma.webtau.reporter;

import com.twosigma.webtau.reporter.TestResultPayload;
import com.twosigma.webtau.reporter.TestStatus;
import com.twosigma.webtau.reporter.TestStep;
import com.twosigma.webtau.reporter.stacktrace.StackTraceCodeEntry;
import com.twosigma.webtau.reporter.stacktrace.StackTraceUtils;
import com.twosigma.webtau.time.Time;
@@ -32,13 +29,9 @@
import java.util.Map;
import java.util.stream.Collectors;

import static com.twosigma.webtau.reporter.TestStatus.Errored;
import static com.twosigma.webtau.reporter.TestStatus.Failed;
import static com.twosigma.webtau.reporter.TestStatus.Passed;
import static com.twosigma.webtau.reporter.TestStatus.Skipped;
import static com.twosigma.webtau.reporter.TestStatus.*;


public class ReportTestEntry {
public class WebTauTest {
private String id;
private String scenario;

@@ -60,7 +53,7 @@
private long startTime;
private long elapsedTime;

public ReportTestEntry(Path workingDir) {
public WebTauTest(Path workingDir) {
this.workingDir = workingDir;
payloads = new ArrayList<>();
steps = new ArrayList<>();
@@ -14,49 +14,47 @@
* limitations under the License.
*/

package com.twosigma.webtau.report;

import com.twosigma.webtau.reporter.TestStatus;
package com.twosigma.webtau.reporter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;

public class ReportTestEntries {
private List<ReportTestEntry> entries;
public class WebTauTestList {
private List<WebTauTest> tests;

public ReportTestEntries() {
entries = Collections.synchronizedList(new ArrayList<>());
public WebTauTestList() {
tests = Collections.synchronizedList(new ArrayList<>());
}

public ReportTestEntries(List<ReportTestEntry> entries) {
this.entries = Collections.synchronizedList(entries);
public WebTauTestList(List<WebTauTest> tests) {
this.tests = Collections.synchronizedList(tests);
}

public void add(ReportTestEntry entry) {
entries.add(entry);
public void add(WebTauTest test) {
tests.add(test);
}

public void forEach(Consumer<ReportTestEntry> action) {
entries.forEach(action);
public void forEach(Consumer<WebTauTest> action) {
tests.forEach(action);
}

public Stream<ReportTestEntry> stream() {
return entries.stream();
public Stream<WebTauTest> stream() {
return tests.stream();
}

public int size() {
return entries.size();
return tests.size();
}

public boolean isEmpty() {
return entries.isEmpty();
return tests.isEmpty();
}

public Stream<ReportTestEntry> withStatus(TestStatus status) {
return entries.stream().filter(e -> e.getTestStatus() == status);
public Stream<WebTauTest> withStatus(TestStatus status) {
return tests.stream().filter(e -> e.getTestStatus() == status);
}

public long countWithStatus(TestStatus status) {
@@ -0,0 +1 @@
com.twosigma.webtau.reporter.TestResultPayloadExtractorTestListener
@@ -2,15 +2,15 @@ package scenarios.rest.report

import com.twosigma.webtau.console.ConsoleOutputs
import com.twosigma.webtau.console.ansi.Color
import com.twosigma.webtau.report.ReportTestEntries
import com.twosigma.webtau.reporter.WebTauReport

import static com.twosigma.webtau.WebTauDsl.cfg

class Report {
static void generateReport(ReportTestEntries entries) {
static void generateReport(WebTauReport report) {
def reportPath = cfg.workingDir.resolve('report.txt')

ConsoleOutputs.out('generating report: ', Color.PURPLE, reportPath)
reportPath.toFile().text = entries.size()
reportPath.toFile().text = report.tests.size()
}
}

0 comments on commit f269b62

Please sign in to comment.
You can’t perform that action at this time.