You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2019/05/05 23:59:10 UTC
[maven-surefire] branch 1546-1222 updated: improved jacoco with
agent and instrumentation
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch 1546-1222
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/1546-1222 by this push:
new 045a398 improved jacoco with agent and instrumentation
045a398 is described below
commit 045a3981bc0c1ce76f7b431d6d62759ad509f20e
Author: tibordigana <ti...@apache.org>
AuthorDate: Mon May 6 01:58:46 2019 +0200
improved jacoco with agent and instrumentation
---
maven-failsafe-plugin/pom.xml | 30 +++++
.../plugin/failsafe/IntegrationTestMojoTest.java | 2 +-
maven-surefire-common/pom.xml | 46 ++++++-
.../plugin/surefire/AbstractSurefireMojoTest.java | 14 ++-
.../maven/plugin/surefire/MojoMocklessTest.java | 68 ++++++++++
.../maven/plugin/surefire/SurefireHelperTest.java | 47 +++++++
maven-surefire-plugin/pom.xml | 26 ++++
.../maven/plugin/surefire/SurefirePluginTest.java | 117 +++++++----------
maven-surefire-report-plugin/pom.xml | 34 +++++
.../plugins/surefire/report/JUnit4SuiteTest.java | 22 ++--
surefire-api/pom.xml | 23 ++++
surefire-booter/pom.xml | 36 ++++++
.../maven/surefire/booter/JUnit4SuiteTest.java | 20 ++-
surefire-extensions-api/pom.xml | 56 +++++++++
surefire-grouper/pom.xml | 26 ++++
surefire-logger-api/pom.xml | 52 ++++++++
.../surefire/log/api/ConsoleLoggerDecorator.java | 2 +-
.../surefire/log/api/ConsoleLoggerUtilsTest.java | 64 ++++++++++
.../plugin/surefire/log/api}/JUnit4SuiteTest.java | 10 +-
.../maven/plugin/surefire/log/api/LevelTest.java | 73 +++++++++++
.../maven/plugin/surefire/log/api/LoggersTest.java | 139 +++++++++++++++++++++
surefire-providers/common-java5/pom.xml | 34 ++++-
surefire-providers/common-junit3/pom.xml | 41 ++++++
surefire-providers/common-junit4/pom.xml | 41 ++++++
surefire-providers/common-junit48/pom.xml | 31 +++++
.../surefire/common/junit48/JUnit4SuiteTest.java | 18 ++-
surefire-providers/surefire-junit-platform/pom.xml | 24 ++++
.../surefire/junitplatform/JUnit47SuiteTest.java | 21 ++--
surefire-providers/surefire-junit3/pom.xml | 41 ++++++
surefire-providers/surefire-junit4/pom.xml | 23 ++++
.../maven/surefire/junit4/JUnit4ProviderTest.java | 6 +-
.../maven/surefire/junit4/JUnit4SuiteTest.java | 10 +-
surefire-providers/surefire-junit47/pom.xml | 31 +++++
.../maven/surefire/junitcore/JUnit47SuiteTest.java | 40 +++---
surefire-providers/surefire-testng-utils/pom.xml | 26 ++++
surefire-providers/surefire-testng/pom.xml | 26 ++++
surefire-report-parser/pom.xml | 24 ++++
.../plugins/surefire/report/JUnit4SuiteTest.java | 20 ++-
38 files changed, 1191 insertions(+), 173 deletions(-)
diff --git a/maven-failsafe-plugin/pom.xml b/maven-failsafe-plugin/pom.xml
index 31dcfbf..9928f11 100644
--- a/maven-failsafe-plugin/pom.xml
+++ b/maven-failsafe-plugin/pom.xml
@@ -86,6 +86,12 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <classifier>runtime</classifier>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -113,6 +119,29 @@
</executions>
</plugin>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
@@ -122,6 +151,7 @@
</dependency>
</dependencies>
<configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
<includes>
<include>**/JUnit4SuiteTest.java</include>
</includes>
diff --git a/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java b/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
index 8414d6b..5e008aa 100644
--- a/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
+++ b/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
@@ -1 +1 @@
-package org.apache.maven.plugin.failsafe;
/*
* 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.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.versioning.Invali
dVersionSpecificationException;
import org.apache.maven.project.MavenProject;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.fest.assertions.Assertions.assertThat;
/**
* @since 2.20
*/
public class IntegrationTestMojoTest
{
private IntegrationTestMojo mojo;
@Before
public void init() throws InvalidVersionSpecificationException, IOException
{
Artifact artifact = new DefaultArtifact( "g", "a", createFromVersionSpec( "1.0" ), "compile", "jar", "", null );
artifact.setFile( new File( "./target/tmp/a-1.0.jar" ) );
new File( "./target/tmp" ).mkdir();
artifact.getFile().createNewFile();
mojo = spy( IntegrationTestMojo.class );
MavenProject project = mo
ck( MavenProject.class );
when( project.getArtifact() ).thenReturn( artifact );
when( mojo.getProject() ).thenReturn( project );
}
@Test
public void shouldBeJar()
{
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
File binaries = mojo.getClassesDirectory();
assertThat( binaries.getName() ).isEqualTo( "a-1.0.jar" );
}
@Test
public void shouldBeAnotherJar()
{
mojo.setClassesDirectory( new File( "./target/another-1.0.jar" ) );
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
File binaries = mojo.getClassesDirectory();
assertThat( binaries.getName() ).isEqualTo( "another-1.0.jar" );
}
@Test
public void shouldBeClasses()
{
mojo.setClassesDirectory( new File( "./target/classes" ) );
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
File binaries = mojo.getClassesDirectory();
assertTha
t( binaries.getName() ).isEqualTo( "classes" );
}
}
\ No newline at end of file
+package org.apache.maven.plugin.failsafe;
/*
* 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.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.versioning.Invali
dVersionSpecificationException;
import org.apache.maven.project.MavenProject;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.fest.assertions.Assertions.assertThat;
/**
* @since 2.20
*/
public class IntegrationTestMojoTest
{
private IntegrationTestMojo mojo;
@Before
public void init() throws InvalidVersionSpecificationException, IOException
{
Artifact artifact = new DefaultArtifact( "g", "a", createFromVersionSpec( "1.0" ), "compile", "jar", "", null );
artifact.setFile( new File( "./target/tmp/a-1.0.jar" ) );
new File( "./target/tmp" ).mkdir();
artifact.getFile().createNewFile();
mojo = new IntegrationTestMojo();
MavenProject project = mock( MavenProject.class );
when( projec
t.getArtifact() ).thenReturn( artifact );
mojo.setProject( project );
}
@Test
public void shouldBeJar()
{
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
File binaries = mojo.getClassesDirectory();
assertThat( binaries.getName() ).isEqualTo( "a-1.0.jar" );
}
@Test
public void shouldBeAnotherJar()
{
mojo.setClassesDirectory( new File( "./target/another-1.0.jar" ) );
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
File binaries = mojo.getClassesDirectory();
assertThat( binaries.getName() ).isEqualTo( "another-1.0.jar" );
}
@Test
public void shouldBeClasses()
{
mojo.setClassesDirectory( new File( "./target/classes" ) );
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
File binaries = mojo.getClassesDirectory();
assertThat( binaries.getName() ).isEqualTo( "classes" );
}
}
\ No newline at end of file
diff --git a/maven-surefire-common/pom.xml b/maven-surefire-common/pom.xml
index 91e12d2..ff7eb97 100644
--- a/maven-surefire-common/pom.xml
+++ b/maven-surefire-common/pom.xml
@@ -120,6 +120,12 @@
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <classifier>runtime</classifier>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -141,12 +147,33 @@
</executions>
</plugin>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-instrumentation</id>
+ <goals>
+ <goal>instrument</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>restore-classes</id>
+ <goals>
+ <goal>restore-instrumented-classes</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <includes>
- <include>**/JUnit4SuiteTest.java</include>
- </includes>
- </configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
@@ -154,6 +181,15 @@
<version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
</dependency>
</dependencies>
+ <configuration>
+ <argLine>${jvm.args.tests}</argLine>
+ <includes>
+ <include>**/JUnit4SuiteTest.java</include>
+ </includes>
+ <systemPropertyVariables>
+ <jacoco-agent.destfile>${project.build.directory}/jacoco.exec</jacoco-agent.destfile>
+ </systemPropertyVariables>
+ </configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
index e193eee..cec6760 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
@@ -1578,7 +1578,7 @@ public class AbstractSurefireMojoTest
}
public static class Mojo
- extends AbstractSurefireMojo
+ extends AbstractSurefireMojo implements SurefireReportParameters
{
private JUnitPlatformProviderInfo createJUnitPlatformProviderInfo( Artifact providerArtifact,
TestClassPath testClasspathWrapper )
@@ -1641,6 +1641,18 @@ public class AbstractSurefireMojoTest
}
@Override
+ public boolean isTestFailureIgnore()
+ {
+ return false;
+ }
+
+ @Override
+ public void setTestFailureIgnore( boolean testFailureIgnore )
+ {
+
+ }
+
+ @Override
public File getBasedir()
{
return null;
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
index f8ba15f..ed846aa 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/MojoMocklessTest.java
@@ -27,6 +27,7 @@ import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.surefire.util.DefaultScanResult;
+import org.apache.maven.toolchain.Toolchain;
import org.junit.Test;
import java.io.File;
@@ -38,10 +39,77 @@ import java.util.zip.ZipOutputStream;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.powermock.reflect.Whitebox.setInternalState;
public class MojoMocklessTest
{
@Test
+ public void testForkMode()
+ {
+ AbstractSurefireMojo surefirePlugin = new Mojo( null, null );
+ setInternalState( surefirePlugin, "toolchain", new MyToolChain() );
+ setInternalState( surefirePlugin, "forkMode", "never" );
+ assertThat( surefirePlugin.getEffectiveForkMode() )
+ .isEqualTo( "once" );
+ }
+
+ @Test
+ public void testForkCountComputation()
+ {
+ AbstractSurefireMojo surefirePlugin = new Mojo( null, null );
+ assertConversionFails( surefirePlugin, "nothing" );
+
+ assertConversionFails( surefirePlugin, "5,0" );
+ assertConversionFails( surefirePlugin, "5.0" );
+ assertConversionFails( surefirePlugin, "5,0C" );
+ assertConversionFails( surefirePlugin, "5.0CC" );
+
+ assertForkCount( surefirePlugin, 5, "5" );
+
+ int availableProcessors = Runtime.getRuntime().availableProcessors();
+ assertForkCount( surefirePlugin, 3 * availableProcessors, "3C" );
+ assertForkCount( surefirePlugin, (int) ( 2.5 * availableProcessors ), "2.5C" );
+ assertForkCount( surefirePlugin, availableProcessors, "1.0001 C" );
+ assertForkCount( surefirePlugin, 1, 1d / ( (double) availableProcessors + 1 ) + "C" );
+ assertForkCount( surefirePlugin, 0, "0 C" );
+ }
+
+ private static void assertForkCount( AbstractSurefireMojo surefirePlugin, int expected, String value )
+ {
+ assertThat( surefirePlugin.convertWithCoreCount( value ) )
+ .isEqualTo( expected );
+ }
+
+ private static void assertConversionFails( AbstractSurefireMojo surefirePlugin, String value )
+ {
+ try
+ {
+ surefirePlugin.convertWithCoreCount( value );
+ }
+ catch ( NumberFormatException e )
+ {
+ return;
+ }
+ fail( "Expected NumberFormatException when converting " + value );
+ }
+
+ private static class MyToolChain implements Toolchain
+ {
+ @Override
+ public String getType()
+ {
+ return null;
+ }
+
+ @Override
+ public String findTool( String s )
+ {
+ return null;
+ }
+ }
+
+ @Test
public void scanDependenciesShouldReturnNull()
throws MojoFailureException
{
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireHelperTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireHelperTest.java
index e5f8eb8..9541d3a 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireHelperTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireHelperTest.java
@@ -19,6 +19,9 @@ package org.apache.maven.plugin.surefire;
* under the License.
*/
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.surefire.AbstractSurefireMojoTest.Mojo;
+import org.apache.maven.surefire.suite.RunResult;
import org.junit.Test;
import java.io.File;
@@ -29,7 +32,9 @@ import static java.util.Collections.addAll;
import static java.util.Collections.singleton;
import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS;
import static org.apache.maven.plugin.surefire.SurefireHelper.escapeToPlatformPath;
+import static org.apache.maven.plugin.surefire.SurefireHelper.reportExecution;
import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
/**
@@ -108,4 +113,46 @@ public class SurefireHelperTest
escaped = escapeToPlatformPath( path );
assertThat( escaped ).isEqualTo( root + "\\" + pathToJar );
}
+
+ @Test
+ public void shouldHandleFailIfNoTests() throws Exception
+ {
+ RunResult summary = new RunResult( 0, 0, 0, 0 );
+ try
+ {
+ Mojo plugin = new Mojo();
+ plugin.setFailIfNoTests( true );
+ reportExecution( plugin, summary, null, null );
+ }
+ catch ( MojoFailureException e )
+ {
+ assertThat( e.getLocalizedMessage() )
+ .isEqualTo( "No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)" );
+ return;
+ }
+ fail( "Expected MojoFailureException with message "
+ + "'No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)'" );
+ }
+
+ @Test
+ public void shouldHandleTestFailure() throws Exception
+ {
+ RunResult summary = new RunResult( 1, 0, 1, 0 );
+ try
+ {
+ reportExecution( new Mojo(), summary, null, null );
+ }
+ catch ( MojoFailureException e )
+ {
+ assertThat( e.getLocalizedMessage() )
+ .isEqualTo( "There are test failures.\n\nPlease refer to null "
+ + "for the individual test results.\nPlease refer to dump files (if any exist) "
+ + "[date].dump, [date]-jvmRun[N].dump and [date].dumpstream." );
+ return;
+ }
+ fail( "Expected MojoFailureException with message "
+ + "'There are test failures.\n\nPlease refer to null "
+ + "for the individual test results.\nPlease refer to dump files (if any exist) "
+ + "[date].dump, [date]-jvmRun[N].dump and [date].dumpstream.'");
+ }
}
diff --git a/maven-surefire-plugin/pom.xml b/maven-surefire-plugin/pom.xml
index ac34a2b..5a1261f 100644
--- a/maven-surefire-plugin/pom.xml
+++ b/maven-surefire-plugin/pom.xml
@@ -86,7 +86,33 @@
</executions>
</plugin>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+ </configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
diff --git a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
index 4cbbf00..6d7b4a3 100644
--- a/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
+++ b/maven-surefire-plugin/src/test/java/org/apache/maven/plugin/surefire/SurefirePluginTest.java
@@ -18,99 +18,70 @@ package org.apache.maven.plugin.surefire;
* under the License.
*/
-
-import java.lang.reflect.Field;
-import org.apache.maven.toolchain.Toolchain;
-
import junit.framework.TestCase;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.surefire.suite.RunResult;
-public class SurefirePluginTest
- extends TestCase
-{
-
- public void testForkMode()
- throws NoSuchFieldException, IllegalAccessException
- {
- SurefirePlugin surefirePlugin = new SurefirePlugin();
- setFieldValue( surefirePlugin, "toolchain", new MyToolChain() );
- setFieldValue( surefirePlugin, "forkMode", "never" );
- assertEquals( "once", surefirePlugin.getEffectiveForkMode() );
- }
+import static org.fest.assertions.Assertions.assertThat;
- public void testForkCountComputation()
+public class SurefirePluginTest extends TestCase
+{
+ public void testDefaultIncludes()
{
- SurefirePlugin surefirePlugin = new SurefirePlugin();
- assertConversionFails( surefirePlugin, "nothing" );
-
- assertConversionFails( surefirePlugin, "5,0" );
- assertConversionFails( surefirePlugin, "5.0" );
- assertConversionFails( surefirePlugin, "5,0C" );
- assertConversionFails( surefirePlugin, "5.0CC" );
-
- assertForkCount( surefirePlugin, 5, "5" );
-
- int availableProcessors = Runtime.getRuntime().availableProcessors();
- assertForkCount( surefirePlugin, 3*availableProcessors, "3C" );
- assertForkCount( surefirePlugin, (int) ( 2.5*availableProcessors ), "2.5C" );
- assertForkCount( surefirePlugin, availableProcessors, "1.0001 C" );
- assertForkCount( surefirePlugin, 1, 1d / ( (double) availableProcessors + 1 ) + "C" );
- assertForkCount( surefirePlugin, 0, "0 C" );
+ assertThat( new SurefirePlugin().getDefaultIncludes() )
+ .containsOnly( "**/Test*.java", "**/*Test.java", "**/*Tests.java", "**/*TestCase.java" );
}
- private void assertForkCount( SurefirePlugin surefirePlugin, int expected, String value )
+ public void testReportSchemaLocation()
{
- assertEquals( expected, surefirePlugin.convertWithCoreCount( value ));
+ assertThat( new SurefirePlugin().getReportSchemaLocation() )
+ .isEqualTo( "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" );
}
- private void assertConversionFails( SurefirePlugin surefirePlugin, String value )
+ public void testFailIfNoTests() throws Exception
{
- try {
- surefirePlugin.convertWithCoreCount( value );
- } catch (NumberFormatException nfe)
+ RunResult runResult = new RunResult( 0, 0, 0, 0 );
+ try
{
- return;
+ SurefirePlugin plugin = new SurefirePlugin();
+ plugin.setFailIfNoTests( true );
+ plugin.handleSummary( runResult, null );
}
- fail( "Expected NumberFormatException when converting " + value );
- }
-
- private void setFieldValue( SurefirePlugin plugin, String fieldName, Object value )
- throws NoSuchFieldException, IllegalAccessException
- {
- Field field = findField( plugin.getClass(), fieldName );
- field.setAccessible( true );
- field.set( plugin, value );
-
- }
-
- private Field findField( Class clazz, String fieldName )
- {
- while ( clazz != null )
+ catch ( MojoFailureException e )
{
- try
- {
- return clazz.getDeclaredField( fieldName );
- }
- catch ( NoSuchFieldException e )
- {
- clazz = clazz.getSuperclass();
- }
+ assertThat( e.getLocalizedMessage() )
+ .isEqualTo( "No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)" );
+ return;
}
- throw new IllegalArgumentException( "Field not found" );
+ fail( "Expected MojoFailureException with message "
+ + "'No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)'" );
}
- private class MyToolChain
- implements Toolchain
+ public void testTestFailure() throws Exception
{
- @Override
- public String getType()
+ RunResult runResult = new RunResult( 1, 0, 1, 0 );
+ try
{
- return null;
+ SurefirePlugin plugin = new SurefirePlugin();
+ plugin.handleSummary( runResult, null );
}
-
- @Override
- public String findTool( String s )
+ catch ( MojoFailureException e )
{
- return null;
+ assertThat( e.getLocalizedMessage() )
+ .isEqualTo( "There are test failures.\n\nPlease refer to null "
+ + "for the individual test results.\nPlease refer to dump files (if any exist) "
+ + "[date].dump, [date]-jvmRun[N].dump and [date].dumpstream." );
+ return;
}
+ fail( "Expected MojoFailureException with message "
+ + "'There are test failures.\n\nPlease refer to null "
+ + "for the individual test results.\nPlease refer to dump files (if any exist) "
+ + "[date].dump, [date]-jvmRun[N].dump and [date].dumpstream.'");
+ }
+
+ public void testPluginName()
+ {
+ assertThat( new SurefirePlugin().getPluginName() )
+ .isEqualTo( "surefire" );
}
}
diff --git a/maven-surefire-report-plugin/pom.xml b/maven-surefire-report-plugin/pom.xml
index 18da79f..5f855d0 100644
--- a/maven-surefire-report-plugin/pom.xml
+++ b/maven-surefire-report-plugin/pom.xml
@@ -179,12 +179,46 @@
</executions>
</plugin>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+ <includes>
+ <include>**/JUnit4SuiteTest.java</include>
+ </includes>
<classpathDependencyExcludes>
<classpathDependencyExclude>org.fusesource.jansi:jansi</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-shadefire</artifactId>
+ <version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
+ </dependency>
+ </dependencies>
</plugin>
</plugins>
</build>
diff --git a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java
similarity index 70%
copy from surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java
copy to maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java
index 142ca9d..5ab3ee1 100644
--- a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java
+++ b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java
@@ -21,26 +21,24 @@ package org.apache.maven.plugins.surefire.report;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
/**
* Adapt the JUnit4 tests which use only annotations to the JUnit3 test suite.
*
* @author Tibor Digana (tibor17)
- * @since 2.21.0
+ * @since 3.0.0-M4
*/
-@Suite.SuiteClasses( {
- ReportTestCaseTest.class,
- ReportTestSuiteTest.class,
- SurefireReportParserTest.class,
- TestSuiteXmlParserTest.class
-} )
-@RunWith( Suite.class )
-public class JUnit4SuiteTest
+public class JUnit4SuiteTest extends TestCase
{
public static Test suite()
{
- return new JUnit4TestAdapter( JUnit4SuiteTest.class );
+ TestSuite suite = new TestSuite();
+ suite.addTest( new JUnit4TestAdapter( Surefire597Test.class ) );
+ suite.addTest( new JUnit4TestAdapter( SurefireSchemaValidationTest.class ) );
+ suite.addTestSuite( Surefire1183Test.class );
+ suite.addTestSuite( SurefireReportMojoTest.class);
+ return suite;
}
}
diff --git a/surefire-api/pom.xml b/surefire-api/pom.xml
index b6e5145..2ce2f68 100644
--- a/surefire-api/pom.xml
+++ b/surefire-api/pom.xml
@@ -64,6 +64,29 @@
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
diff --git a/surefire-booter/pom.xml b/surefire-booter/pom.xml
index 4ca6536..1fe33e7 100644
--- a/surefire-booter/pom.xml
+++ b/surefire-booter/pom.xml
@@ -86,11 +86,43 @@
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <classifier>runtime</classifier>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-instrumentation</id>
+ <goals>
+ <goal>instrument</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>restore-classes</id>
+ <goals>
+ <goal>restore-instrumented-classes</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
@@ -100,9 +132,13 @@
</dependency>
</dependencies>
<configuration>
+ <argLine>${jvm.args.tests}</argLine>
<includes>
<include>**/JUnit4SuiteTest.java</include>
</includes>
+ <systemPropertyVariables>
+ <jacoco-agent.destfile>${project.build.directory}/jacoco.exec</jacoco-agent.destfile>
+ </systemPropertyVariables>
</configuration>
</plugin>
<plugin>
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/JUnit4SuiteTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/JUnit4SuiteTest.java
index a45f252..ff731c4 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/JUnit4SuiteTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/JUnit4SuiteTest.java
@@ -21,8 +21,8 @@ package org.apache.maven.surefire.booter;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
/**
* Adapt the JUnit4 tests which use only annotations to the JUnit3 test suite.
@@ -30,17 +30,15 @@ import org.junit.runners.Suite;
* @author Tibor Digana (tibor17)
* @since 2.19
*/
-@Suite.SuiteClasses( {
- ClasspathTest.class,
- PropertiesWrapperTest.class,
- PpidCheckerTest.class,
- SystemUtilsTest.class
-} )
-@RunWith( Suite.class )
-public class JUnit4SuiteTest
+public class JUnit4SuiteTest extends TestCase
{
public static Test suite()
{
- return new JUnit4TestAdapter( JUnit4SuiteTest.class );
+ TestSuite suite = new TestSuite();
+ suite.addTest( new JUnit4TestAdapter( PpidCheckerTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( SystemUtilsTest.class ) );
+ suite.addTestSuite( ClasspathTest.class );
+ suite.addTestSuite( PropertiesWrapperTest.class );
+ return suite;
}
}
diff --git a/surefire-extensions-api/pom.xml b/surefire-extensions-api/pom.xml
index 6daae03..db0aafa 100644
--- a/surefire-extensions-api/pom.xml
+++ b/surefire-extensions-api/pom.xml
@@ -44,6 +44,62 @@
<artifactId>plexus-component-annotations</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <classifier>runtime</classifier>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-instrumentation</id>
+ <!--
+ phase: the order of the plugins matters and maven-plugin-plugin must be before jacoco plugin
+ -->
+ <goals>
+ <goal>instrument</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>restore-classes</id>
+ <goals>
+ <goal>restore-instrumented-classes</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-shadefire</artifactId>
+ <version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
+ </dependency>
+ </dependencies>
+ <configuration>
+ <argLine>${jvm.args.tests}</argLine>
+ <systemPropertyVariables>
+ <jacoco-agent.destfile>${project.build.directory}/jacoco.exec</jacoco-agent.destfile>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
\ No newline at end of file
diff --git a/surefire-grouper/pom.xml b/surefire-grouper/pom.xml
index 9aa676c..d3ae750 100644
--- a/surefire-grouper/pom.xml
+++ b/surefire-grouper/pom.xml
@@ -52,7 +52,33 @@
</executions>
</plugin>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+ </configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
diff --git a/surefire-logger-api/pom.xml b/surefire-logger-api/pom.xml
index 4a56f3a..429c754 100644
--- a/surefire-logger-api/pom.xml
+++ b/surefire-logger-api/pom.xml
@@ -49,4 +49,56 @@
</developer>
</developers>
+ <dependencies>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+ <includes>
+ <include>**/JUnit4SuiteTest.java</include>
+ </includes>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-shadefire</artifactId>
+ <version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
diff --git a/surefire-logger-api/src/main/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerDecorator.java b/surefire-logger-api/src/main/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerDecorator.java
index 02105fa..5938fc1 100644
--- a/surefire-logger-api/src/main/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerDecorator.java
+++ b/surefire-logger-api/src/main/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerDecorator.java
@@ -1 +1 @@
-package org.apache.maven.plugin.surefire.log.api;
/*
* 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.
*/
/**
* Decorator around {@link ConsoleLogger}.
* This class is loaded in the isolated ClassLoader and the child logger in the in-plugi
n ClassLoader.
*
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
* @since 2.20
*/
public final class ConsoleLoggerDecorator
implements ConsoleLogger
{
private final Object logger;
public ConsoleLoggerDecorator( Object logger )
{
if ( logger == null )
{
throw new NullPointerException( "logger argument is null in " + ConsoleLoggerDecorator.class );
}
this.logger = logger;
}
@Override
public boolean isDebugEnabled()
{
try
{
return (Boolean) logger.getClass()
.getMethod( "isDebugEnabled" )
.invoke( logger );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public void debug( String message )
{
try
{
logger.getClass()
.getMethod( "debug", String.cl
ass )
.invoke( logger, message );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public boolean isInfoEnabled()
{
try
{
return (Boolean) logger.getClass()
.getMethod( "isInfoEnabled" )
.invoke( logger );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public void info( String message )
{
try
{
logger.getClass()
.getMethod( "info", String.class )
.invoke( logger, message );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public boolean isWarnEnabled()
{
try
{
r
eturn (Boolean) logger.getClass()
.getMethod( "isWarnEnabled" )
.invoke( logger );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public void warning( String message )
{
try
{
logger.getClass()
.getMethod( "warning", String.class )
.invoke( logger, message );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public boolean isErrorEnabled()
{
try
{
return (Boolean) logger.getClass()
.getMethod( "isErrorEnabled" )
.invoke( logger );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public void error( String message )
{
try
{
logger.getClass()
.getMethod( "error", String.class )
.invoke( logger, message );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public void error( String message, Throwable t )
{
try
{
logger.getClass()
.getMethod( "error", String.class, Throwable.class )
.invoke( logger, message, t );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public void error( Throwable t )
{
try
{
logger.getClass()
.getMethod( "error", Throwable.class )
.invoke( logger, t );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
}
\ No newline at end of file
+package org.apache.maven.plugin.surefire.log.api;
/*
* 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.
*/
/**
* Decorator around {@link ConsoleLogger}.
* This class is loaded in the isolated ClassLoader and the child logger in the in-plugi
n ClassLoader.
*
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
* @since 2.20
*/
public final class ConsoleLoggerDecorator
implements ConsoleLogger
{
private final Object logger;
public ConsoleLoggerDecorator( Object logger )
{
if ( logger == null )
{
throw new NullPointerException( "logger argument is null in " + ConsoleLoggerDecorator.class );
}
this.logger = logger;
}
@Override
public boolean isDebugEnabled()
{
return invokeReturnedBoolean( "isDebugEnabled" );
}
@Override
public void debug( String message )
{
invokeWithMessage( message, "debug" );
}
@Override
public boolean isInfoEnabled()
{
return invokeReturnedBoolean( "isInfoEnabled" );
}
@Override
public void info( String message )
{
invokeWithMessage( message, "info" );
}
@Override
public boolean isWarnEnabled()
{
return invokeReturnedBoolean( "isWarnEnabled" );
}
@Override
public void warning( String message )
{
invokeWithMessage( message, "warning" );
}
@Override
public boolean isErrorEnabled()
{
return invokeReturnedBoolean( "isErrorEnabled" );
}
@Override
public void error( String message )
{
invokeWithMessage( message, "error" );
}
@Override
public void error( String message, Throwable t )
{
try
{
logger.getClass()
.getMethod( "error", String.class, Throwable.class )
.invoke( logger, message, t );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
@Override
public void error( Throwable t )
{
try
{
logger.getClass()
.getMethod( "error", Throwable.class )
.invoke( logger, t );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
private boolean invokeReturnedBoolean( String isErrorEnabled )
{
try
{
return (Boolean) logger.getClass()
.getMethod( isErrorEnabled )
.invoke( logger );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
private void invokeWithMessage( String message, String error )
{
try
{
logger.getClass()
.getMethod( error, String.class )
.invoke( logger, message );
}
catch ( Exception e )
{
throw new IllegalStateException( e.getLocalizedMessage(), e );
}
}
}
\ No newline at end of file
diff --git a/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerUtilsTest.java b/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerUtilsTest.java
new file mode 100644
index 0000000..902a17e
--- /dev/null
+++ b/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/ConsoleLoggerUtilsTest.java
@@ -0,0 +1,64 @@
+package org.apache.maven.plugin.surefire.log.api;
+
+/*
+ * 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.junit.Test;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+/**
+ * Tests for {@link ConsoleLoggerUtils}.
+ */
+public class ConsoleLoggerUtilsTest
+{
+ @Test
+ public void shouldPrintStacktraceAsString()
+ {
+ Exception e = new IllegalArgumentException( "wrong param" );
+ String msg = ConsoleLoggerUtils.toString( e );
+
+ StringWriter text = new StringWriter();
+ PrintWriter writer = new PrintWriter( text );
+ e.printStackTrace( writer );
+ String s = text.toString();
+
+ assertThat( msg )
+ .isEqualTo( s );
+ }
+
+ @Test
+ public void shouldPrintStacktracWithMessageAsString()
+ {
+ Exception e = new IllegalArgumentException( "wrong param" );
+ String msg = ConsoleLoggerUtils.toString( "issue", e );
+
+ StringWriter text = new StringWriter();
+ PrintWriter writer = new PrintWriter( text );
+ writer.println( "issue" );
+ e.printStackTrace( writer );
+ String s = text.toString();
+
+ assertThat( msg )
+ .isEqualTo( s );
+ }
+}
diff --git a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4SuiteTest.java b/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/JUnit4SuiteTest.java
similarity index 81%
copy from surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4SuiteTest.java
copy to surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/JUnit4SuiteTest.java
index 0666fcb..69665a3 100644
--- a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4SuiteTest.java
+++ b/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/JUnit4SuiteTest.java
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.junit4;
+package org.apache.maven.plugin.surefire.log.api;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -21,16 +21,20 @@ package org.apache.maven.surefire.junit4;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
+import junit.framework.TestCase;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
/**
* Adapt the JUnit4 tests which use only annotations to the JUnit3 test suite.
+ *
+ * @author Tibor Digana (tibor17)
+ * @since 3.0.0-M4
*/
-@SuiteClasses( JUnit4ProviderTest.class )
+@SuiteClasses( { ConsoleLoggerUtilsTest.class, LevelTest.class, LoggersTest.class } )
@RunWith( Suite.class )
-public class JUnit4SuiteTest
+public class JUnit4SuiteTest extends TestCase
{
public static Test suite()
{
diff --git a/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/LevelTest.java b/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/LevelTest.java
new file mode 100644
index 0000000..0f48880
--- /dev/null
+++ b/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/LevelTest.java
@@ -0,0 +1,73 @@
+package org.apache.maven.plugin.surefire.log.api;
+
+/*
+ * 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.junit.Test;
+
+import static org.apache.maven.plugin.surefire.log.api.Level.resolveLevel;
+import static org.fest.assertions.Assertions.assertThat;
+
+/**
+ * Tests for {@link Level}.
+ */
+public class LevelTest
+{
+ @Test
+ public void shouldHaveSuccess()
+ {
+ Level level = resolveLevel( true, false, false, false, false );
+ assertThat( level ).isEqualTo( Level.SUCCESS );
+ }
+
+ @Test
+ public void shouldNotHaveSuccess()
+ {
+ Level level = resolveLevel( false, false, false, false, false );
+ assertThat( level ).isEqualTo( Level.NO_COLOR );
+ }
+
+ @Test
+ public void shouldBeFailure()
+ {
+ Level level = resolveLevel( false, true, false, false, false );
+ assertThat( level ).isEqualTo( Level.FAILURE );
+ }
+
+ @Test
+ public void shouldBeError()
+ {
+ Level level = resolveLevel( false, false, true, false, false );
+ assertThat( level ).isEqualTo( Level.FAILURE );
+ }
+
+ @Test
+ public void shouldBeSkipped()
+ {
+ Level level = resolveLevel( false, false, false, true, false );
+ assertThat( level ).isEqualTo( Level.UNSTABLE );
+ }
+
+ @Test
+ public void shouldBeFlake()
+ {
+ Level level = resolveLevel( false, false, false, false, true );
+ assertThat( level ).isEqualTo( Level.UNSTABLE );
+ }
+}
diff --git a/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/LoggersTest.java b/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/LoggersTest.java
new file mode 100644
index 0000000..7de9148
--- /dev/null
+++ b/surefire-logger-api/src/test/java/org/apache/maven/plugin/surefire/log/api/LoggersTest.java
@@ -0,0 +1,139 @@
+package org.apache.maven.plugin.surefire.log.api;
+
+/*
+ * 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.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+import org.mockito.internal.matchers.CapturesArguments;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests for {@link ConsoleLoggerDecorator}, {@link NullConsoleLogger} and {@link PrintStreamLogger}.
+ */
+public class LoggersTest
+{
+ @Test
+ public void testPrintStreamLogger()
+ {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ PrintStream printStream = new PrintStream( outputStream );
+ PrintStreamLogger logger = new PrintStreamLogger( printStream );
+
+
+ assertThat( logger.isErrorEnabled() ).isTrue();
+ assertThat( logger.isWarnEnabled() ).isTrue();
+ assertThat( logger.isInfoEnabled() ).isTrue();
+ assertThat( logger.isDebugEnabled() ).isTrue();
+
+ logger.error( "error" );
+ logger.debug( "debug" );
+ logger.info( "info" );
+ logger.warning( "warning" );
+
+ String line = System.lineSeparator();
+ assertThat( outputStream.toString() )
+ .isEqualTo( "error" + line + "debug" + line + "info" + line + "warning" + line );
+
+ Exception e = new Exception( "exception" );
+ outputStream.reset();
+ logger.error( e );
+ assertThat( outputStream.toString() )
+ .contains( "java.lang.Exception: exception" )
+ .contains( "at " + getClass().getName() + ".testPrintStreamLogger(LoggersTest.java:63)" );
+ }
+
+ @Test( expected = NullPointerException.class )
+ public void shouldThrowNPE()
+ {
+ new ConsoleLoggerDecorator( null );
+ }
+
+ @Test
+ public void testDecorator()
+ {
+ ConsoleLogger logger = mock( ConsoleLogger.class );
+ ConsoleLoggerDecorator decorator = new ConsoleLoggerDecorator( logger );
+
+ assertThat( decorator.isDebugEnabled() ).isFalse();
+ when( logger.isDebugEnabled() ).thenReturn( true );
+ assertThat( decorator.isDebugEnabled() ).isTrue();
+
+ assertThat( decorator.isInfoEnabled() ).isFalse();
+ when( logger.isInfoEnabled() ).thenReturn( true );
+ assertThat( decorator.isInfoEnabled() ).isTrue();
+
+ assertThat( decorator.isWarnEnabled() ).isFalse();
+ when( logger.isWarnEnabled() ).thenReturn( true );
+ assertThat( decorator.isWarnEnabled() ).isTrue();
+
+ assertThat( decorator.isErrorEnabled() ).isFalse();
+ when( logger.isErrorEnabled() ).thenReturn( true );
+ assertThat( decorator.isErrorEnabled() ).isTrue();
+
+ ArgumentCaptor<String> argumentMsg = ArgumentCaptor.forClass( String.class );
+ decorator.debug( "debug" );
+ verify( logger, times( 1 ) ).debug( argumentMsg.capture() );
+ assertThat( argumentMsg.getAllValues() ).hasSize( 1 );
+ assertThat( argumentMsg.getAllValues().get( 0 ) ).isEqualTo( "debug" );
+
+ argumentMsg = ArgumentCaptor.forClass( String.class );
+ decorator.info( "info" );
+ verify( logger, times( 1 ) ).info( argumentMsg.capture() );
+ assertThat( argumentMsg.getAllValues() ).hasSize( 1 );
+ assertThat( argumentMsg.getAllValues().get( 0 ) ).isEqualTo( "info" );
+
+ argumentMsg = ArgumentCaptor.forClass( String.class );
+ decorator.warning( "warning" );
+ verify( logger, times( 1 ) ).warning( argumentMsg.capture() );
+ assertThat( argumentMsg.getAllValues() ).hasSize( 1 );
+ assertThat( argumentMsg.getAllValues().get( 0 ) ).isEqualTo( "warning" );
+
+ argumentMsg = ArgumentCaptor.forClass( String.class );
+ decorator.error( "error" );
+ verify( logger, times( 1 ) ).error( argumentMsg.capture() );
+ assertThat( argumentMsg.getAllValues() ).hasSize( 1 );
+ assertThat( argumentMsg.getAllValues().get( 0 ) ).isEqualTo( "error" );
+
+ ArgumentCaptor<Throwable> argumentThrowable = ArgumentCaptor.forClass( Throwable.class );
+ argumentMsg = ArgumentCaptor.forClass( String.class );
+ Exception e = new Exception();
+ decorator.error( "error", e );
+ verify( logger, times( 1 ) ).error( argumentMsg.capture(), argumentThrowable.capture() );
+ assertThat( argumentMsg.getAllValues() ).hasSize( 1 );
+ assertThat( argumentMsg.getAllValues().get( 0 ) ).isEqualTo( "error" );
+ assertThat( argumentThrowable.getAllValues() ).hasSize( 1 );
+ assertThat( argumentThrowable.getAllValues().get( 0 ) ).isSameAs( e );
+
+ argumentThrowable = ArgumentCaptor.forClass( Throwable.class );
+ decorator.error( e );
+ verify( logger, times( 1 ) ).error( argumentThrowable.capture() );
+ assertThat( argumentThrowable.getAllValues() ).hasSize( 1 );
+ assertThat( argumentThrowable.getAllValues().get( 0 ) ).isSameAs( e );
+ }
+}
diff --git a/surefire-providers/common-java5/pom.xml b/surefire-providers/common-java5/pom.xml
index ba44a98..7ecf6af 100644
--- a/surefire-providers/common-java5/pom.xml
+++ b/surefire-providers/common-java5/pom.xml
@@ -41,6 +41,29 @@
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
@@ -68,10 +91,15 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <excludes>
- <exclude>**/fixture/**</exclude>
- </excludes>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
</configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-shadefire</artifactId>
+ <version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
+ </dependency>
+ </dependencies>
</plugin>
</plugins>
</build>
diff --git a/surefire-providers/common-junit3/pom.xml b/surefire-providers/common-junit3/pom.xml
index 2089eec..9d314ba 100644
--- a/surefire-providers/common-junit3/pom.xml
+++ b/surefire-providers/common-junit3/pom.xml
@@ -40,4 +40,45 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-shadefire</artifactId>
+ <version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
diff --git a/surefire-providers/common-junit4/pom.xml b/surefire-providers/common-junit4/pom.xml
index 0af781c..0bcd734 100644
--- a/surefire-providers/common-junit4/pom.xml
+++ b/surefire-providers/common-junit4/pom.xml
@@ -49,4 +49,45 @@
<version>${project.version}</version>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-shadefire</artifactId>
+ <version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/surefire-providers/common-junit48/pom.xml b/surefire-providers/common-junit48/pom.xml
index ddfdf75..569a1a5 100644
--- a/surefire-providers/common-junit48/pom.xml
+++ b/surefire-providers/common-junit48/pom.xml
@@ -58,12 +58,43 @@
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
<includes>
<include>**/JUnit4SuiteTest.java</include>
</includes>
</configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-shadefire</artifactId>
+ <version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
+ </dependency>
+ </dependencies>
</plugin>
</plugins>
</build>
diff --git a/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/JUnit4SuiteTest.java b/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/JUnit4SuiteTest.java
index 547c381..191e1e8 100644
--- a/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/JUnit4SuiteTest.java
+++ b/surefire-providers/common-junit48/src/test/java/org/apache/maven/surefire/common/junit48/JUnit4SuiteTest.java
@@ -21,8 +21,8 @@ package org.apache.maven.surefire.common.junit48;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
/**
* Adapt the JUnit4 tests which use only annotations to the JUnit3 test suite.
@@ -30,16 +30,14 @@ import org.junit.runners.Suite;
* @author Tibor Digana (tibor17)
* @since 2.19
*/
-@Suite.SuiteClasses( {
- FilterFactoryTest.class,
- JUnit48ReflectorTest.class,
- JUnit48TestCheckerTest.class
-} )
-@RunWith( Suite.class )
-public class JUnit4SuiteTest
+public class JUnit4SuiteTest extends TestCase
{
public static Test suite()
{
- return new JUnit4TestAdapter( JUnit4SuiteTest.class );
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite( JUnit48ReflectorTest.class );
+ suite.addTest( new JUnit4TestAdapter( JUnit48TestCheckerTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( FilterFactoryTest.class ) );
+ return suite;
}
}
diff --git a/surefire-providers/surefire-junit-platform/pom.xml b/surefire-providers/surefire-junit-platform/pom.xml
index eaaaeef..bdf5c9a 100644
--- a/surefire-providers/surefire-junit-platform/pom.xml
+++ b/surefire-providers/surefire-junit-platform/pom.xml
@@ -115,6 +115,29 @@
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<executions>
@@ -143,6 +166,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
<configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
<jvm>${java.home}/bin/java</jvm>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<includes>
diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnit47SuiteTest.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnit47SuiteTest.java
index d0d4af9..7db25c9 100644
--- a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnit47SuiteTest.java
+++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnit47SuiteTest.java
@@ -21,26 +21,23 @@ package org.apache.maven.surefire.junitplatform;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
/**
* Adapt the JUnit4 tests which use only annotations to the JUnit3 test suite.
*
* @since 3.0.0-M4
*/
-@SuiteClasses( {
- JUnitPlatformProviderTest.class,
- RunListenerAdapterTest.class,
- TestMethodFilterTest.class,
- TestPlanScannerFilterTest.class
-} )
-@RunWith( Suite.class )
-public class JUnit47SuiteTest
+public class JUnit47SuiteTest extends TestCase
{
public static Test suite()
{
- return new JUnit4TestAdapter( JUnit47SuiteTest.class );
+ TestSuite suite = new TestSuite();
+ suite.addTest( new JUnit4TestAdapter( JUnitPlatformProviderTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( RunListenerAdapterTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( TestMethodFilterTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( TestPlanScannerFilterTest.class ) );
+ return suite;
}
}
diff --git a/surefire-providers/surefire-junit3/pom.xml b/surefire-providers/surefire-junit3/pom.xml
index 44d608e..a163a7f 100644
--- a/surefire-providers/surefire-junit3/pom.xml
+++ b/surefire-providers/surefire-junit3/pom.xml
@@ -44,4 +44,45 @@
<version>${project.version}</version>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-shadefire</artifactId>
+ <version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/surefire-providers/surefire-junit4/pom.xml b/surefire-providers/surefire-junit4/pom.xml
index 1155cc9..2981dab 100644
--- a/surefire-providers/surefire-junit4/pom.xml
+++ b/surefire-providers/surefire-junit4/pom.xml
@@ -52,6 +52,29 @@
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
diff --git a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java b/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java
index bf6cafc..2e411b9 100644
--- a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java
+++ b/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java
@@ -19,9 +19,9 @@ package org.apache.maven.surefire.junit4;
* under the License.
*/
-import junit.framework.TestCase;
import org.apache.maven.surefire.booter.BaseProviderFactory;
import org.apache.maven.surefire.testset.TestRequest;
+import org.junit.Test;
import org.junit.runner.Description;
import java.util.HashMap;
@@ -29,14 +29,15 @@ import java.util.HashMap;
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.assertNotNull;
import static org.junit.runner.Description.createSuiteDescription;
/**
* @author Kristian Rosenvold
*/
public class JUnit4ProviderTest
- extends TestCase
{
+ @Test
public void testCreateProvider()
{
assertNotNull( getJUnit4Provider() );
@@ -51,6 +52,7 @@ public class JUnit4ProviderTest
return new JUnit4Provider( providerParameters );
}
+ @Test
public void testShouldCreateDescription()
{
class A {
diff --git a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4SuiteTest.java b/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4SuiteTest.java
index 0666fcb..2d4fb72 100644
--- a/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4SuiteTest.java
+++ b/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4SuiteTest.java
@@ -21,19 +21,15 @@ package org.apache.maven.surefire.junit4;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
+import junit.framework.TestCase;
/**
* Adapt the JUnit4 tests which use only annotations to the JUnit3 test suite.
*/
-@SuiteClasses( JUnit4ProviderTest.class )
-@RunWith( Suite.class )
-public class JUnit4SuiteTest
+public class JUnit4SuiteTest extends TestCase
{
public static Test suite()
{
- return new JUnit4TestAdapter( JUnit4SuiteTest.class );
+ return new JUnit4TestAdapter( JUnit4ProviderTest.class );
}
}
diff --git a/surefire-providers/surefire-junit47/pom.xml b/surefire-providers/surefire-junit47/pom.xml
index 2c36b5a..af32cc0 100644
--- a/surefire-providers/surefire-junit47/pom.xml
+++ b/surefire-providers/surefire-junit47/pom.xml
@@ -59,6 +59,29 @@
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
@@ -155,11 +178,19 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<includes>
<include>**/JUnit47SuiteTest.java</include>
</includes>
</configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-shadefire</artifactId>
+ <version>3.0.0-M3</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
+ </dependency>
+ </dependencies>
</plugin>
</plugins>
</build>
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit47SuiteTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit47SuiteTest.java
index 9954627..02534ee 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit47SuiteTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit47SuiteTest.java
@@ -21,12 +21,12 @@ package org.apache.maven.surefire.junitcore;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
import org.apache.maven.surefire.junitcore.pc.OptimizedParallelComputerTest;
import org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilderTest;
import org.apache.maven.surefire.junitcore.pc.ParallelComputerUtilTest;
import org.apache.maven.surefire.junitcore.pc.SchedulingStrategiesTest;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
/**
* Adapt the JUnit47 tests which use only annotations to the JUnit3 test suite.
@@ -34,27 +34,25 @@ import org.junit.runners.Suite;
* @author Tibor Digana (tibor17)
* @since 2.16
*/
-@Suite.SuiteClasses( {
- Surefire746Test.class,
- Surefire813IncorrectResultTest.class,
- ParallelComputerUtilTest.class,
- ParallelComputerBuilderTest.class,
- SchedulingStrategiesTest.class,
- OptimizedParallelComputerTest.class,
- ConcurrentRunListenerTest.class,
- ConfigurableParallelComputerTest.class,
- JUnit4Reflector481Test.class,
- JUnitCoreParametersTest.class,
- JUnitCoreRunListenerTest.class,
- MavenSurefireJUnit47RunnerTest.class,
- MavenSurefireJUnit48RunnerTest.class,
- TestMethodTest.class
-} )
-@RunWith( Suite.class )
-public class JUnit47SuiteTest
+public class JUnit47SuiteTest extends TestCase
{
public static Test suite()
{
- return new JUnit4TestAdapter( JUnit47SuiteTest.class );
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite( ConcurrentRunListenerTest.class );
+ suite.addTestSuite( ConfigurableParallelComputerTest.class );
+ suite.addTestSuite( JUnitCoreRunListenerTest.class );
+ suite.addTestSuite( MavenSurefireJUnit47RunnerTest.class );
+ suite.addTestSuite( MavenSurefireJUnit48RunnerTest.class );
+ suite.addTestSuite( TestMethodTest.class );
+ suite.addTest( new JUnit4TestAdapter( Surefire746Test.class ) );
+ suite.addTest( new JUnit4TestAdapter( Surefire813IncorrectResultTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( ParallelComputerUtilTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( ParallelComputerBuilderTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( SchedulingStrategiesTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( OptimizedParallelComputerTest.class ) );
+ suite.addTest( new JUnit4TestAdapter( JUnit4Reflector481Test.class ) );
+ suite.addTest( new JUnit4TestAdapter( JUnitCoreParametersTest.class ) );
+ return suite;
}
}
diff --git a/surefire-providers/surefire-testng-utils/pom.xml b/surefire-providers/surefire-testng-utils/pom.xml
index b75979c..bfc4b55 100644
--- a/surefire-providers/surefire-testng-utils/pom.xml
+++ b/surefire-providers/surefire-testng-utils/pom.xml
@@ -55,7 +55,33 @@
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+ </configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
diff --git a/surefire-providers/surefire-testng/pom.xml b/surefire-providers/surefire-testng/pom.xml
index 8c29441..d3d308d 100644
--- a/surefire-providers/surefire-testng/pom.xml
+++ b/surefire-providers/surefire-testng/pom.xml
@@ -60,7 +60,33 @@
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+ </configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
diff --git a/surefire-report-parser/pom.xml b/surefire-report-parser/pom.xml
index 8c3f767..d1e2854 100644
--- a/surefire-report-parser/pom.xml
+++ b/surefire-report-parser/pom.xml
@@ -54,6 +54,29 @@
<build>
<plugins>
<plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>jacoco-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <!--todo remove-->
+ <id>jacoco-report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <propertyName>jacoco.agent</propertyName>
+ </configuration>
+ </plugin>
+ <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
@@ -63,6 +86,7 @@
</dependency>
</dependencies>
<configuration>
+ <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
<includes>
<include>**/JUnit4SuiteTest.java</include>
</includes>
diff --git a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java
index 142ca9d..8c143dd 100644
--- a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java
+++ b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/JUnit4SuiteTest.java
@@ -21,8 +21,8 @@ package org.apache.maven.plugins.surefire.report;
import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
/**
* Adapt the JUnit4 tests which use only annotations to the JUnit3 test suite.
@@ -30,17 +30,15 @@ import org.junit.runners.Suite;
* @author Tibor Digana (tibor17)
* @since 2.21.0
*/
-@Suite.SuiteClasses( {
- ReportTestCaseTest.class,
- ReportTestSuiteTest.class,
- SurefireReportParserTest.class,
- TestSuiteXmlParserTest.class
-} )
-@RunWith( Suite.class )
-public class JUnit4SuiteTest
+public class JUnit4SuiteTest extends TestCase
{
public static Test suite()
{
- return new JUnit4TestAdapter( JUnit4SuiteTest.class );
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite( ReportTestCaseTest.class );
+ suite.addTestSuite( ReportTestSuiteTest.class );
+ suite.addTestSuite( SurefireReportParserTest.class );
+ suite.addTest( new JUnit4TestAdapter( TestSuiteXmlParserTest.class ) );
+ return suite;
}
}