How the flexmojos-test-harness works
As everybody who has built Flexmojos locally will have noticed, there is one module that's build time exceeds that of all the others by far: The flexmojos-test-harness
When looking at this module I bet noone immediately understood how it works. In general there are a big number of Java tests in src/test/java and a whole bunch of maven projects under "projects". But how do these pieces work together?
Well when building the following things happen (Reference to the Maven default phases: http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference) :
- During the "initialize" phase of the Maven build, the "maven-invoker-plugin" populates a local maven repo under "target/local-repository" by copying a whole bunch of artifacts from your normal local maven repo (All those packages referenced in the "<xml>" tags of the test-harness' pom.xml
- During the "generate-test-resources" phase of the Maven build, the "maven-dependency-plugin" is used to download a binary distribution of maven and to "install" this in "target/apache-maven-3.0.4".
- During the "process-test-resources" phase of the Maven build, two steps are performed:
all the "properties" files in "src/test/resources" are copied to the default "target/test-classes" directory. This currently only applies to "baseTest.properties". As "filtering" is set to true, all Maven variables are replaced by the actual values of the current build.
fake-maven=${project.build.directory}/apache-maven-${maven-version} fake-repo=${project.build.directory}/local-repository version=${project.version} projects-source=${project.basedir}/projects projects-target=${project.build.directory}/projects flex-version=${flex.sdk.version} maven-site-plugin.version=${maven-site-plugin.version}
becomes:
fake-maven=E:\\Test\\flexmojos\\flexmojos-testing\\flexmojos-test-harness\\target/apache-maven-3.0.4 fake-repo=E:\\Test\\flexmojos\\flexmojos-testing\\flexmojos-test-harness\\target/local-repository version=5.1-beta-SNAPSHOT projects-source=E:\\Test\\flexmojos\\flexmojos-testing\\flexmojos-test-harness/projects projects-target=E:\\Test\\flexmojos\\flexmojos-testing\\flexmojos-test-harness\\target/projects flex-version=4.5.1.21328 maven-site-plugin.version=3.0-beta-3
These properties can then be used by AbstractFlexMojosTest to configure the tests.
The "settings.xml" in "src/test/resources" is copied to the previously created maven installation in "target/apache-maven-3.0.4/conf", overwriting the initial settings.xml that was contained in the distribution.
- After this initial setup the Test classes are compiled in the "test-compile" phase.
- In the "test" phase the real magic starts. Surefire executes all the Tests in "src/test/java". All of these tests extend "AbstractFlexMojosTest" which takes care of the details of executing maven in "target/apache-maven-3.0.4" to execute the "install" target of the projects in the "projects" directory.