On 6 October 2014 10:31, Robert Mark Bram <robertmarkb...@gmail.com> wrote:

> Hi All,
>
> A couple of questions about integration tests..
>
>
> 1) Default vs non-default plugins
> I needed to include the maven-failsafe-plugin plugin to introduce
> integration tests into my project, but I didn't need to introduce the
> maven-surefire-plugin to my pom.xml for unit tests. Fair enough, but
> how do I know which plugins are included by default?
>

> suddenly a White Rabbit with pink eyes ran close by Alice

In your pom.xml there is a xml node /project/packaging that specifies the
lifecycle for your project.

You may not have set the value to anything, as the default if unspecified
is: jar

> There was nothing so very remarkable in that; nor did Alice think it so
very much out of the way to hear the Rabbit say to itself "Oh dear! Oh
dear! I shall be too late!"

Maven consults all the registered extensions and the core functionality to
see what lifecycles are registered for the packaging of the module it is
building.

In general it will end up here:
https://github.com/apache/maven/blob/276c7636d342f6d01353ae862b56fa89614b17a9/maven-core/src/main/resources/META-INF/plexus/components.xml#L33

> but, when the Rabbit actually took a watch out of its waistcoat-pocket,
and looked at it, and then hurried on, Alice started to her feet, for it
flashed across her mind that she had never before seen a rabbit with either
a waistcoat-pocket, or a watch to take out of it, and burning with
curiosity, she ran across the field after it, and was just in time to see
it pop down a large rabbit-hole under the hedge.

Once Maven has determined the lifecycle(s) that apply to your module, it
then looks up the phases and goals that you specified when invoking Maven.

>From this list of phases and goals it starts to construct the build plan...

Conceptually, at the start the build plan is just the list of phases to
execute.

So for example you type: `mvn clean install clean deploy site-deploy`

Then Maven says, ok clean comes from the `clean` lifecycle, and it is the
second phase... so we will start off with: pre-clean, clean

Next we need install, so that's from the default lifecycle and we will add
in the phases: validate, initialize, generate-sources, process-sources,
generate-resources, process-resources, compile, process-classes,
generate-test-sources, process-test-sources, generate-test-resources,
process-test-resources, test-compile, process-test-classes, test,
prepare-package, package, pre-integration-test, integration-test,
post-integration-test, verify, install

Then we need another clean... at this point our list will be looking like:
pre-clean, clean, validate, initialize, generate-sources, process-sources,
generate-resources, process-resources, compile, process-classes,
generate-test-sources, process-test-sources, generate-test-resources,
process-test-resources, test-compile, process-test-classes, test,
prepare-package, package, pre-integration-test, integration-test,
post-integration-test, verify, install, pre-clean, clean

Then we need to go all the way up to deploy... so we'll have: pre-clean,
clean, validate, initialize, generate-sources, process-sources,
generate-resources, process-resources, compile, process-classes,
generate-test-sources, process-test-sources, generate-test-resources,
process-test-resources, test-compile, process-test-classes, test,
prepare-package, package, pre-integration-test, integration-test,
post-integration-test, verify, install, pre-clean, clean, validate,
initialize, generate-sources, process-sources, generate-resources,
process-resources, compile, process-classes, generate-test-sources,
process-test-sources, generate-test-resources, process-test-resources,
test-compile, process-test-classes, test, prepare-package, package,
pre-integration-test, integration-test, post-integration-test, verify,
install, deploy

And finally we need to run up the site lifecycle as far as site-deploy...
so now the complete list of phases to execute in order are: pre-clean,
clean, validate, initialize, generate-sources, process-sources,
generate-resources, process-resources, compile, process-classes,
generate-test-sources, process-test-sources, generate-test-resources,
process-test-resources, test-compile, process-test-classes, test,
prepare-package, package, pre-integration-test, integration-test,
post-integration-test, verify, install, pre-clean, clean, validate,
initialize, generate-sources, process-sources, generate-resources,
process-resources, compile, process-classes, generate-test-sources,
process-test-sources, generate-test-resources, process-test-resources,
test-compile, process-test-classes, test, prepare-package, package,
pre-integration-test, integration-test, post-integration-test, verify,
install, deploy, pre-site, site, post-site, site-deploy

> In another moment down went Alice after it, never once considering how in
the world she was to get out again.

Now Maven needs to decide exactly what it should do for each of those
phases.

So it starts by considering the default bindings: These again are
determined by the packaging. In the case of the jar packaging from core
that is defined here:
https://github.com/apache/maven/blob/276c7636d342f6d01353ae862b56fa89614b17a9/maven-core/src/main/resources/META-INF/plexus/default-bindings.xml

So everywhere that Maven sees the `test` phase it will add a binding of
surefire:
https://github.com/apache/maven/blob/276c7636d342f6d01353ae862b56fa89614b17a9/maven-core/src/main/resources/META-INF/plexus/default-bindings.xml#L82
the binding defined the default plugin version but if you specify a
different plugin version in your pom then the default is overridden.

Next Maven looks at the effective pom for your project to see if there are
any executions that are bound to phases.

At the end of this process, maven now has a list of ordered plugin goal
executions... and away it goes


>
> 2) Just run integration tests?
> I can see that unit tests are all classes with names like *Test.java
> and integration tests are all classes with names like IT.java. But mvn
> verify and mvn test seem to run all tests (unit and integrations). Is
> there a way to run just one or the other?
>

tweaking of
http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#skipTests
should get you there!


>
> 3) Run integration tests after compile?
> The real reason for question 2 is that I wish to run integration tests
> only after I have deployed the new application to ensure the
> integration tests run on the server with the new content. Is there a
> way to do this?
>
>
Sounds like you should consult my answer to a related question:
http://stackoverflow.com/questions/16935290/maven-deploy-webapp-to-tomcat-before-junit-test/16936585#16936585


> Thanks for any assistance!
>
> Rob
> :)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
> For additional commands, e-mail: users-h...@maven.apache.org
>
>

Reply via email to