[ACCEPTED]-How can I test a maven archetype that I've just created?-archetypes

Accepted answer
Score: 16

UPDATE 2013: This is now much easier than the other answers suggest.

https://issues.apache.org/jira/browse/ARCHETYPE-334 was completed in Aug 2011

To use, simply 18 place the word install inside the goal.txt file mentioned 17 above, and the tests from the project you 16 are archetyping will be invoked as part 15 of a normal build. (And/or verify in the case 14 of OP.)

However, if you new to making archetypes 13 be aware that this popular mini-guide is out of date and, while 12 it will work for making an archetype it 11 will not work for having archetype integration 10 tests run. You should instead be creating 9 an archetype-metadata.xml file as described here. (This is much nicer 8 to work with as well, as it uses file sets!)

Also 7 note these integration tests do not respond 6 to -DskipTests but this can be remedied as follows:

<build>
  <plugins>

    <plugin>
      <artifactId>maven-archetype-plugin</artifactId>
      <version>2.2</version>
      <configuration>
        <skip>${skipTests}</skip>
      </configuration>        
    </plugin>

  </plugins>
</build>

(Although 5 this looks like it skips the entire plugin, it 4 actually works, probably because it falls 3 back to a legacy mode; whereas I could 2 not find any successful way to skip just 1 the integration-test goal execution using code above.)

Score: 3

beside the the approach of using the maven-invoker-plugin, we 10 are using a different approach. With the 9 help of the Maven Verifier you can test 8 your maven plugins and archetypes easily. Just 7 add the following dependency into your pom 6 of your maven test project:

<dependency>                                
  <groupId>org.apache.maven.shared</groupId>
  <artifactId>maven-verifier</artifactId>   
  <version>1.2</version>                    
</dependency>                               

Now you are able 5 to use

org.apache.maven.it.Verifier

into your normal JUnit Tests. With 4 the verifier you can run maven goals and 3 some assertions about the result. For a 2 complete example just check out the integration 1 test maven modules of our javascript-archetypes: https://github.com/akquinet/javascript-archetypes

Score: 2

I was struggling a little with this myself, and 6 figured that when using current v2.3 of 5 the maven-archetype-plugin, in addition 4 to a src/test/resources/projects/first/goal.txt, one 3 also needs a src/test/resources/projects/first/archetype.properties 2 containing something like this:

sourceEncoding=UTF-8
groupId=integrationtest.group
artifactId=integrationtest.artifactId
version=1.0.0-SNAPSHOT
package=org.eclipse.xtend.xtend-archetype.integrationtest
packageInPathFormat=org/eclipse/xtend/xtend-archetype/integrationtest

This pull request illustrates 1 a complete working example.

Score: 0

I guess that would be a scenario for a continuous 4 integration server like hudson.

You'd define a 3 job that

  1. empties a directory (shell script)
  2. creates a new project based on the archetype (mvn archetype:generate)
  3. runs the project (mvn package)

While this could probably somehow be 2 fit into one maven lifecycle, it would feel 1 like an awful mess. Use CI instead.

Score: 0

I see the archetype:integration-test goal, but 15 it doesn't seem to be doing what I want.

Unless 14 I misunderstood what you want, the archetype:integration-test goal seems 13 to be a very good solution:

Execute the archetype 12 integration tests, consisting of a creation 11 of a project from the current archetype with 10 defined properties and optional comparison 9 with reference copy. An IT consists of 8 a directory in src/test/resources/projects containing:

  • goal.txt (content actually not used, but future version should interpret it as a goal to run against the generated project: see ARCHETYPE-334),
  • archetype.properties with properties for project generation,
  • optional reference/ directory containing a reference copy of the expected project created from the IT.

According 7 to the above description, this goals allows 6 precisely to run Integration Test(s) to 5 check a project generated with the current 4 archetype against an expected result and 3 this looks like a clean, simple, self contained 2 way to test an archetype.

Why is this approach 1 not satisfying? What did I miss?

More Related questions