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

Add options to print stack trace / stdout / stderr on error or failure #39

Merged
merged 4 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,25 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

settings.xml
settings.xml

### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
.project
.classpath

# Locally stored "Eclipse launch configurations"
*.launch

# Java annotation processor (APT)
.factorypath
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Configure your POM like the following
<disable>true</disable>
</consoleOutputReporter>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporterUnicode">
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<theme>UNICODE</theme>
</statelessTestsetInfoReporter>
</configuration>
</plugin>
Expand All @@ -70,6 +71,42 @@ Configure your POM like the following
</consoleOutputReporter>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<theme>ASCII</theme>
</statelessTestsetInfoReporter>
</configuration>
</plugin>
```

## Failure details

By default, `<consoleOutputReporter><disable>true</disable></consoleOutputReporter>` disables all console output. To debug test failures, it may be useful to see the console output and stack traces when a test fails. To do so, you can configure this extension like this:

```xml
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<configuration>
<reportFormat>plain</reportFormat>
<consoleOutputReporter>
<disable>true</disable>
</consoleOutputReporter>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<printStacktrackeOnError>true</printStacktrackeOnError>
<printStacktrackeOnFailure>true</printStacktrackeOnFailure>
<printStdoutOnError>true</printStdoutOnError>
<printStdoutOnFailure>true</printStdoutOnFailure>
<printStdoutOnSuccess>false</printStdoutOnSuccess>
<printStderrOnError>true</printStderrOnError>
<printStderrOnFailure>true</printStderrOnFailure>
<printStderrOnSuccess>false</printStderrOnSuccess>
</statelessTestsetInfoReporter>
</configuration>
</plugin>
Expand Down
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>1.1.0</version>
<version>1.2.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>maven-surefire-junit5-tree-reporter</name>
Expand All @@ -22,7 +22,7 @@
</maven-surefire.testsetInfoReporter>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -152,6 +152,9 @@
<goals>
<goal>jar</goal>
</goals>
<configuration>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
</configuration>
</execution>
</executions>
</plugin>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,42 +1,157 @@
package org.apache.maven.plugin.surefire.extensions.junit5;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.plugin.surefire.loader.SurefireClassLoaderModifier;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.report.ConsoleTreeReporterAscii;
import org.apache.maven.plugin.surefire.report.ConsoleTreeReporter;
import org.apache.maven.plugin.surefire.report.ReporterOptions;
import org.apache.maven.plugin.surefire.report.TestSetStats;
import org.apache.maven.plugin.surefire.report.Theme;
import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;

/**
* Extension of {@link JUnit5StatelessTestsetInfoReporter file and console reporter of test-set} for JUnit5.
* Extension of {@link JUnit5StatelessTestsetInfoReporter file and console
* reporter of test-set} for JUnit5.
*
* @author <a href="mailto:[email protected]">Fabrício Yamamoto (fabriciorby)</a>
* @author <a href="mailto:[email protected]">Fabrício Yamamoto
* (fabriciorby)</a>
*/
public class JUnit5StatelessTestsetInfoTreeReporter extends JUnit5StatelessTestsetInfoReporterBase {
public class JUnit5StatelessTestsetInfoTreeReporter extends JUnit5StatelessTestsetInfoReporter {
private boolean printStacktraceOnError;
private boolean printStacktraceOnFailure;
private boolean printStderrOnError;
private boolean printStderrOnFailure;
private boolean printStderrOnSuccess;
private boolean printStdoutOnError;
private boolean printStdoutOnFailure;
private boolean printStdoutOnSuccess;
private Theme theme = Theme.ASCII;

@Override
public Object clone(ClassLoader target) {
try {
new SurefireClassLoaderModifier(target).addThisToSurefireClassLoader();

Object clone = super.clone(target);

Class<?> cls = clone.getClass();
cls.getMethod("setPrintStacktraceOnError", boolean.class).invoke(clone, isPrintStacktraceOnError());
cls.getMethod("setPrintStacktraceOnFailure", boolean.class).invoke(clone, isPrintStacktraceOnFailure());
cls.getMethod("setPrintStderrOnError", boolean.class).invoke(clone, isPrintStderrOnError());
cls.getMethod("setPrintStderrOnFailure", boolean.class).invoke(clone, isPrintStderrOnFailure());
cls.getMethod("setPrintStderrOnSuccess", boolean.class).invoke(clone, isPrintStderrOnSuccess());
cls.getMethod("setPrintStdoutOnError", boolean.class).invoke(clone, isPrintStdoutOnError());
cls.getMethod("setPrintStdoutOnFailure", boolean.class).invoke(clone, isPrintStdoutOnFailure());
cls.getMethod("setPrintStdoutOnSuccess", boolean.class).invoke(clone, isPrintStdoutOnSuccess());
cls.getMethod("setTheme", Theme.class).invoke(clone, getTheme());

return clone;
} catch (ReflectiveOperationException e) {
throw new IllegalStateException(e.getLocalizedMessage());
}
}

@Override
public StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSetStats> createListener(
ConsoleLogger logger) {
return new ConsoleTreeReporterAscii(logger, isUsePhrasedClassNameInRunning(),
isUsePhrasedClassNameInTestCaseSummary());
return new ConsoleTreeReporter(logger, newReporterOptions());
}

public Theme getTheme() {
return theme;
}

public boolean isPrintStacktraceOnError() {
return printStacktraceOnError;
}

public boolean isPrintStacktraceOnFailure() {
return printStacktraceOnFailure;
}

public boolean isPrintStderrOnError() {
return printStderrOnError;
}

public boolean isPrintStderrOnFailure() {
return printStderrOnFailure;
}

public boolean isPrintStderrOnSuccess() {
return printStderrOnSuccess;
}

public boolean isPrintStdoutOnError() {
return printStdoutOnError;
}

public boolean isPrintStdoutOnFailure() {
return printStdoutOnFailure;
}

public boolean isPrintStdoutOnSuccess() {
return printStdoutOnSuccess;
}

public void setPrintStacktraceOnError(boolean printStacktraceOnError) {
this.printStacktraceOnError = printStacktraceOnError;
}

public void setPrintStacktraceOnFailure(boolean printStacktraceOnFailure) {
this.printStacktraceOnFailure = printStacktraceOnFailure;
}

public void setPrintStderrOnError(boolean printStderrOnError) {
this.printStderrOnError = printStderrOnError;
}

public void setPrintStderrOnFailure(boolean printStderrOnFailure) {
this.printStderrOnFailure = printStderrOnFailure;
}

public void setPrintStderrOnSuccess(boolean printStderrOnSuccess) {
this.printStderrOnSuccess = printStderrOnSuccess;
}

public void setPrintStdoutOnError(boolean printStdoutOnError) {
this.printStdoutOnError = printStdoutOnError;
}

public void setPrintStdoutOnFailure(boolean printStdoutOnFailure) {
this.printStdoutOnFailure = printStdoutOnFailure;
}

public void setPrintStdoutOnSuccess(boolean printStdoutOnSuccess) {
this.printStdoutOnSuccess = printStdoutOnSuccess;
}

public void setTheme(Theme theme) {
this.theme = theme;
}

@Override
public String toString() {
return this.getClass().getSimpleName() + "{"
+ "disable=" + isDisable()
+ ", usePhrasedFileName=" + isUsePhrasedFileName()
+ ", usePhrasedClassNameInRunning=" + isUsePhrasedClassNameInRunning()
+ ", usePhrasedClassNameInTestCaseSummary=" + isUsePhrasedClassNameInTestCaseSummary()
+ "}";
}

private ReporterOptions newReporterOptions() {
return ReporterOptions.builder()
.printStacktraceOnError(isPrintStacktraceOnError())
.printStacktraceOnFailure(isPrintStacktraceOnFailure())
.printStderrOnError(isPrintStderrOnError())
.printStderrOnFailure(isPrintStderrOnFailure())
.printStderrOnSuccess(isPrintStderrOnSuccess())
.printStdoutOnError(isPrintStdoutOnError())
.printStdoutOnFailure(isPrintStdoutOnFailure())
.printStdoutOnSuccess(isPrintStdoutOnSuccess())
.usePhrasedClassNameInRunning(isUsePhrasedClassNameInRunning())
.usePhrasedClassNameInTestCaseSummary(isUsePhrasedClassNameInTestCaseSummary())
.theme(getTheme())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,17 @@
package org.apache.maven.plugin.surefire.extensions.junit5;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.report.ConsoleTreeReporterUnicode;
import org.apache.maven.plugin.surefire.report.TestSetStats;
import org.apache.maven.plugin.surefire.report.WrappedReportEntry;
import org.apache.maven.surefire.extensions.StatelessTestsetInfoConsoleReportEventListener;
import org.apache.maven.plugin.surefire.report.Theme;

/**
* Extension of {@link JUnit5StatelessTestsetInfoReporter file and console reporter of test-set} for JUnit5.
*
* @deprecated Use {@link JUnit5StatelessTestsetInfoTreeReporter} and set the parameter {@code theme} to {@code UNICODE}.
* @author <a href="mailto:[email protected]">Fabrício Yamamoto (fabriciorby)</a>
*/
public class JUnit5StatelessTestsetInfoTreeReporterUnicode extends JUnit5StatelessTestsetInfoReporterBase {

@Deprecated
public class JUnit5StatelessTestsetInfoTreeReporterUnicode extends JUnit5StatelessTestsetInfoTreeReporter {
@Override
public StatelessTestsetInfoConsoleReportEventListener<WrappedReportEntry, TestSetStats> createListener(
ConsoleLogger logger) {
return new ConsoleTreeReporterUnicode(logger, isUsePhrasedClassNameInRunning(),
isUsePhrasedClassNameInTestCaseSummary());
public Theme getTheme() {
return Theme.UNICODE;
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.apache.maven.plugin.surefire.loader;

import org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporterBase;

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.stream.Stream;

import org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoReporter;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -28,7 +28,7 @@

/**
* Class created to modify the Surefire ClassLoader during Runtime.
* Needed for {@link JUnit5StatelessTestsetInfoReporterBase#clone()} method,
* Needed for {@link JUnit5StatelessTestsetInfoReporter#clone()} method,
* which is used when the unit tests are running using multiple threads.
*
* @author <a href="mailto:[email protected]">Fabrício Yamamoto (fabriciorby)</a>
Expand Down
Loading