Class JUnit4Mojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
-
Field Summary
FieldsModifier and TypeFieldDescriptionAdditional elements to be appended to the classpath.private StringArbitrary JVM options to set on the command line.private org.codehaus.plexus.configuration.PlexusConfigurationRaw assertions configuration.private org.codehaus.plexus.configuration.PlexusConfigurationRaw balancers configuration.private FileThe directory containing generated classes of the project being tested.List of dependencies to exclude from the test classpath.private StringA dependency scope to exclude from the test classpath.private BooleanEnables a debug stream from each forked JVM.private static final StringDefault target in the generated ANT file.private FileBase directory to invoke slave VMs in.private floatSpecifies the ratio of suites moved to dynamic assignment list.private static final String[]An empty String[].An empty Mapinvalid input: '<'String, String>.Adds an environment variable to any forked JVM.A list of <exclude> elements specifying the tests (by pattern) that should be excluded in testing.private StringProperty to set to "true" if there is a failure in a test.private booleanStop the build process if there were failures or errors during test execution.private longSets the heartbeat used to detect inactive/ hung forked tests (JVMs) to the given number of seconds.private StringWhat to do when no tests were executed (all tests were ignored)? Possible values: ignore, fail, warn.A list of <include> elements specifying the tests (by pattern) that should be included in testing.private booleanIf set totrueeach forked JVM gets a separate working directory under whatever is set indir.private StringSpecifies the name of the JUnit artifact used for running tests.private StringThe command used to invoke the Java Virtual Machine, default is 'java'.private String[]Add an additional argument to any forked JVM.private StringWhat should be done on unexpected JVM output? JVM may write directly to the original descriptors, bypassing redirections of System.out and System.err.private booleanSet to true to leave temporary files for diagnostics.private org.codehaus.plexus.configuration.PlexusConfigurationRaw listeners configuration.private StringSet the maximum memory to be used by all forked JVMs.private org.apache.maven.artifact.metadata.ArtifactMetadataSourceFor retrieval of artifact's metadata.private BooleanSet new environment for the forked process?private StringSets the action performed when current work directory for a forked JVM is not empty andisolateWorkingDirectoriesis set to true.private StringProject packaging mode to skip POM-projectsprivate StringThe number of parallel f.Map of plugin artifacts.private StringInitializes custom prefix for all junit4 properties.private booleanPrints the summary of all executed, ignored etc.private org.apache.maven.project.MavenProjectThe Maven project objectMap of project artifacts.private org.apache.maven.repository.RepositorySystemRepository.private org.apache.maven.artifact.resolver.ArtifactResolverprivate StringInitial random seed used for shuffling test suites and other sources of pseudo-randomness.private org.apache.maven.execution.MavenSessionThe current build session instance.private booleanPredictably shuffle tests order after balancing.private booleanSet this to "true" to skip running tests, but still compile them.private StringSets the property prefix to which test statistics are saved.private FileThis parameter adds a listener emitting surefire-compatible XMLs if no other listeners are added.private booleanIf set to true, any sysout and syserr calls will be written to original output and error streams (and in effect will appear as "jvm output".Adds a system property to any forked JVM.private FileThe directory to store temporary files in.private FileThe directory containing generated test classes of the project being tested.private booleanAllows or disallow duplicate suite names in resource collections.private org.codehaus.plexus.configuration.PlexusConfigurationRaw section to copy/paste into ANT-driver.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddArtifactClassPath(org.dom4j.Element cp, org.apache.maven.artifact.Artifact artifact) Append classpath elements of the given artefact to classpath.private voidappendRawXml(org.codehaus.plexus.configuration.PlexusConfiguration config, org.dom4j.Element elem) Append raw XML configuration.private voidcheckVersion(String artifactName, String versionSpec, org.apache.maven.artifact.Artifact artifact) EnsureartifactNamematches versionversionSpec.private org.dom4j.ElementcreateDocumentSkeleton(org.dom4j.Document doc) Creates a skeleton of a single-target ANT build file with JUnit4 task inside.private FilecreateTemporaryAntFile(org.dom4j.Document doc) Create a temporary ANT file for executing JUnit4 ANT task.voidexecute()Run the mojo.private Set<org.apache.maven.artifact.Artifact> filterArtifacts(org.dom4j.Element cp, Set<org.apache.maven.artifact.Artifact> artifacts, org.apache.maven.artifact.resolver.filter.ArtifactFilter filter) Return a new set containing only the artifacts accepted by the given filter.private voidpopulateJUnitElement(org.dom4j.Element junit4) Populate junit4 task with attributes and values.private org.apache.maven.artifact.resolver.ArtifactResolutionResultresolveArtifact(org.apache.maven.artifact.Artifact artifact, org.apache.maven.artifact.Artifact... filtered) Resolve a given artifact given exclusion list.private voidsetupTestClasspath(org.dom4j.Element junit4) Setup the classpath used for tests.private voidsetupTestInput(org.dom4j.Element junit4) Setup the input test suites (classes locations and patterns).private voidInitial validation of input parameters and configuration.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
EMPTY_STRING_ARRAY
An empty String[]. -
EMPTY_STRING_STRING_MAP
-
DEFAULT_TARGET
-
project
@Parameter(property="project", readonly=true, required=true) private org.apache.maven.project.MavenProject projectThe Maven project object -
dir
Base directory to invoke slave VMs in. Also noteisolateWorkingDirectoriesparameter. -
tempDir
The directory to store temporary files in. -
parallelism
The number of parallel f. Can be set to a constant "max" for the number of cores returned fromRuntime.availableProcessors()or "auto" for sensible defaults depending on the number of cores. The default is a single subprocess.Note that this setting forks physical JVM processes so it multiplies the requirements for heap memory, IO, etc.
-
failureProperty
Property to set to "true" if there is a failure in a test. The use of this property is discouraged in Maven (builds should be declarative). -
seed
Initial random seed used for shuffling test suites and other sources of pseudo-randomness. If not set, any random value is set.The seed's format is compatible with
RandomizedRunnerso that seed can be fixed for suites and methods alike. Unless the global prefix of randomized testing properties is changed, the seed can be overridden using "tests.seed" property. -
shuffleOnSlave
@Parameter(defaultValue="true") private boolean shuffleOnSlavePredictably shuffle tests order after balancing. This will help in spreading lighter and heavier tests over a single slave's execution timeline while still keeping the same tests order depending on the seed. -
printSummary
@Parameter(defaultValue="true") private boolean printSummaryPrints the summary of all executed, ignored etc. tests at the end. -
haltOnFailure
@Parameter(defaultValue="true") private boolean haltOnFailureStop the build process if there were failures or errors during test execution. -
isolateWorkingDirectories
@Parameter(defaultValue="true") private boolean isolateWorkingDirectoriesIf set totrueeach forked JVM gets a separate working directory under whatever is set indir. The directory naming for each JVM follows: "Jnum", where num is the forked JVM's number. Directories are created automatically and removed unlessleaveTemporaryis set totrue. -
onNonEmptyWorkDirectory
Sets the action performed when current work directory for a forked JVM is not empty andisolateWorkingDirectoriesis set to true. -
sysouts
@Parameter(defaultValue="false") private boolean sysoutsIf set to true, any sysout and syserr calls will be written to original output and error streams (and in effect will appear as "jvm output". By default sysout and syserrs are captured and proxied to the event stream to be synchronized with other test events but occasionally one may want to synchronize them with direct JVM output (to synchronize with compiler output or GC output for example). -
dynamicAssignmentRatio
@Parameter(defaultValue="0.25") private float dynamicAssignmentRatioSpecifies the ratio of suites moved to dynamic assignment list. A dynamic assignment list dispatches suites to the first idle slave JVM. Theoretically this is an optimal strategy, but it is usually better to have some static assignments to avoid communication costs.A ratio of 0 means only static assignments are used. A ratio of 1 means only dynamic assignments are used.
The list of dynamic assignments is sorted by decreasing cost (always) and is inherently prone to race conditions in distributing suites. Should there be an error based on suite-dependency it will not be directly repeatable. In such case use the per-slave-jvm list of suites file dumped to disk for each slave JVM. (see
leaveTemporaryparameter). -
maxMemory
Set the maximum memory to be used by all forked JVMs. The value as defined by -mx or -Xmx in the java command line options. -
leaveTemporary
@Parameter private boolean leaveTemporarySet to true to leave temporary files for diagnostics. -
jvmArgs
Add an additional argument to any forked JVM. -
argLine
Arbitrary JVM options to set on the command line. -
systemProperties
-
environmentVariables
-
jvm
The command used to invoke the Java Virtual Machine, default is 'java'. The command is resolved by java.lang.Runtime.exec(). -
testClassesDirectory
The directory containing generated test classes of the project being tested. This will be included at the beginning of the test classpath. -
classesDirectory
The directory containing generated classes of the project being tested. This will be included aftertestClassesDirectory. -
includes
A list of <include> elements specifying the tests (by pattern) that should be included in testing. When not specified defaults to:<include>**/*Test.class</include> <include>**/Test*.class</include>
Note that this may result in nested classes being included for tests. Use proper exclusion patterns. -
excludes
-
surefireReportsDirectory
@Parameter(defaultValue="${project.build.directory}/surefire-reports") private File surefireReportsDirectoryThis parameter adds a listener emitting surefire-compatible XMLs if no other listeners are added. If there are any configured listeners, this parameter is omitted (you can add a maven-compatible listener manually). -
junitArtifactName
@Parameter(property="junitArtifactName", defaultValue="junit:junit") private String junitArtifactNameSpecifies the name of the JUnit artifact used for running tests. JUnit dependency must be in at least version 4.10. -
jvmOutputAction
What should be done on unexpected JVM output? JVM may write directly to the original descriptors, bypassing redirections of System.out and System.err. Typically, these messages will be important and should fail the build (permgen space exceeded, compiler errors, crash dumps). However, certain legitimate logs (gc activity, class loading logs) are also printed to these streams so sometimes the output can be ignored.Allowed values (any comma-delimited combination of): ignore, pipe, warn, fail.
-
uniqueSuiteNames
@Parameter(defaultValue="true") private boolean uniqueSuiteNamesAllows or disallow duplicate suite names in resource collections. By default this option istruebecause certain ANT-compatible report types (like XML reports) will have a problem with duplicate suite names (will overwrite files). -
listeners
@Parameter private org.codehaus.plexus.configuration.PlexusConfiguration listenersRaw listeners configuration. Same XML as for ANT. -
assertions
@Parameter private org.codehaus.plexus.configuration.PlexusConfiguration assertionsRaw assertions configuration. Same XML as for ANT. -
balancers
@Parameter private org.codehaus.plexus.configuration.PlexusConfiguration balancersRaw balancers configuration. Same XML as for ANT. -
verbatim
@Parameter private org.codehaus.plexus.configuration.PlexusConfiguration verbatimRaw section to copy/paste into ANT-driver. -
heartbeat
@Parameter(defaultValue="0") private long heartbeatSets the heartbeat used to detect inactive/ hung forked tests (JVMs) to the given number of seconds. The heartbeat detects no-event intervals and will report them to listeners. Notably,TextReportreport will emit heartbeat information (to a file or console).Setting the heartbeat to zero means no detection.
-
skipTests
@Parameter(property="skipTests", defaultValue="false") private boolean skipTestsSet this to "true" to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite convenient on occasion. -
packaging
Project packaging mode to skip POM-projects -
classpathDependencyExcludes
List of dependencies to exclude from the test classpath. Each dependency string must follow the format groupId:artifactId. For example: org.acme:project-aThis is modeled after surefire. An excluded dependency does not mean its transitive dependencies will also be excluded.
-
classpathDependencyScopeExclude
A dependency scope to exclude from the test classpath. The scope can be one of the following scopes:- compile - system, provided, compile
- runtime - compile, runtime
- test - system, provided, compile, runtime, test
-
additionalClasspathElements
-
prefix
Initializes custom prefix for all junit4 properties. This must be consistent across all junit4 invocations if done from the same classpath. Use only when REALLY needed. -
debugStream
Enables a debug stream from each forked JVM. This will create an additional file next to each events file. For debugging the framework only, not a general-purpose setting. -
newEnvironment
Set new environment for the forked process? -
ifNoTests
What to do when no tests were executed (all tests were ignored)? Possible values: ignore, fail, warn. -
statsPropertyPrefix
Sets the property prefix to which test statistics are saved. -
pluginArtifactMap
-
projectArtifactMap
-
session
@Parameter(property="session", required=true, readonly=true) private org.apache.maven.execution.MavenSession sessionThe current build session instance. -
repositorySystem
@Component private org.apache.maven.repository.RepositorySystem repositorySystemRepository. -
metadataSource
@Component private org.apache.maven.artifact.metadata.ArtifactMetadataSource metadataSourceFor retrieval of artifact's metadata. -
resolver
@Component private org.apache.maven.artifact.resolver.ArtifactResolver resolver
-
-
Constructor Details
-
JUnit4Mojo
public JUnit4Mojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionRun the mojo.- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
validateParameters
private void validateParameters() throws org.apache.maven.plugin.MojoExecutionExceptionInitial validation of input parameters and configuration.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
checkVersion
-
populateJUnitElement
private void populateJUnitElement(org.dom4j.Element junit4) Populate junit4 task with attributes and values. -
appendRawXml
private void appendRawXml(org.codehaus.plexus.configuration.PlexusConfiguration config, org.dom4j.Element elem) Append raw XML configuration. -
createTemporaryAntFile
Create a temporary ANT file for executing JUnit4 ANT task.- Throws:
IOException
-
createDocumentSkeleton
private org.dom4j.Element createDocumentSkeleton(org.dom4j.Document doc) Creates a skeleton of a single-target ANT build file with JUnit4 task inside. -
addArtifactClassPath
private void addArtifactClassPath(org.dom4j.Element cp, org.apache.maven.artifact.Artifact artifact) Append classpath elements of the given artefact to classpath. -
resolveArtifact
private org.apache.maven.artifact.resolver.ArtifactResolutionResult resolveArtifact(org.apache.maven.artifact.Artifact artifact, org.apache.maven.artifact.Artifact... filtered) Resolve a given artifact given exclusion list. (copied from surefire). -
setupTestClasspath
private void setupTestClasspath(org.dom4j.Element junit4) Setup the classpath used for tests. -
filterArtifacts
-
setupTestInput
private void setupTestInput(org.dom4j.Element junit4) Setup the input test suites (classes locations and patterns).
-