Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

Naming your Test

In the past, tests were numbered sequentially (it001,it002, etc). This becomes problematic because it's not always obvious what the issue is related to the test. More importantly, it's hard to create and submit sequential tests via patches because non-committers have no way to reserve the next number. This leads to extra work to apply the patch.

 New tests should be named using the Jira Issue id along with a meaningful name. This name should typically be the subject of the issue or a subset. It should be informative of the issue but not excessively long. Therefore a good name would be: mng1234-groupIdOrderIsBackwards.

This name is typically used in several places of the test: the folder in core-integration-tests/src/test/resources/ that contains the sample project along with the name of the junit class used to invoke the sample project and check the results.

Sample IT Project

A sample project has been created to aid in IT test creation. It can be retrieved using svn hereor viewed with your browser here.

Sample IT Archetype 

This project has also been converted into an archetype to make it even easier to use. (NOTE: This is currently not deployed and bugs prevent this from being usable right now. Use the Sample IT project for now and skip this section -Brianf 8/8/07)

Using ArchetypeNG To create a sample from the archetype

It would be helpful to review the archetypeNG plugin tutorial here: [insert url of site when it lands at apache] 

The maven-archetypeng-plugin is currently a snapshot. You will need to add the snapshot repository to your settings to be able to retreive the plugin and the archetype (when it gets deployed).

           <id>Maven Snapshots</id>
  <!--need to activate my profile unless I want to type 'mvn -Pmaven-snapshots' all the time-->

The archetypeNG plugin maintains a list of known archetype groups for interactive prompting. The next step is to add the IT group:

ARCHETYPE-82: You must manually create archetype.xml in your $HOME/.m2 folder and it must minimally contain the following:

<?xml version="1.0" encoding="UTF-8"?><archetype-registry>
    <ArchetypeRepository id="central">

mvn archetypeng:add-groups -Dgroups=org.apache.maven.its

Successful output:

E:\svn\Maven\atest>mvn archetypeng:add-groups -Dgroups=org.apache.maven.its
Using maven.home=c:\Program Files\maven2\bin\\..
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetypeng'.
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetypeng:add-groups] (aggregator-style)
[INFO] ----------------------------------------------------------------------------
[INFO] [archetypeng:add-groups]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Wed Aug 08 21:58:57 EDT 2007
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------

Now you can create the archetype project:

mvn archetype:create

ARCHETYPE-83: prevents us from continuing with this story...

Tour of the Sample Project

The sample IT project contains the following files: 

|   pom.xml
        |   \---org
        |       \---apache
        |           \---maven
        |               \---integrationTests
	|                     |
                |   pom.xml
                |   readme.txt
                |   |   pom.xml
                |   |
                |   +---src
                |      \---main
                |          \---resources
                |                  rule_set.xml
                |                  stc_checks.xml
                    |   pom.xml

    src/test/java/contains a junit file used to execute the sample project. It is heavily commented to guide you along. Stop here and Take a lookbefore continuing.

    src/test/resources contains a sample project tree that will be invoked to test our condition. The sample consists of a few modules, first an extension (checkstyle-assembly) that is jarred up and installed into the repository. Then a second invocation is made on a project that uses the extension (checkstyle-test)

The sample IT project uses the simplest method of using the verifier, that is the sample build fails if the test should fail. More complicated ITs can be created with beanshell scripts to check complex conditions. (Example Needed) (Link to verifier docs)

Once your IT is complete, you should be able to execute it:

>mvn test
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Integration Tests
[INFO]    task-segment: [test]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] No sources to compile
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Compiling 1 source file to E:\svn\Maven\maven-it-tests\test\artifact\target\test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: E:\svn\Maven\maven-it-tests\test\artifact\target\surefire-reports

 T E S T S
Running mypackage.MavenITmngXXXXDescriptionOfProblemTest
mngXXXXDescriptionOfProblem(testitMNGxxxx).. Ok
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 16.802 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25 seconds
[INFO] Finished at: Wed Aug 08 22:47:44 EDT 2007
[INFO] Final Memory: 4M/10M
[INFO] ------------------------------------------------------------------------

Submitting your IT Test

Now that your IT is complete, create a zip, tgz or some other *normal* archive of your test and attach it to your Jira issue.

If you are a Maven committer, read the next section to see how to integrate your test into the core, or to apply someone else's test.

Integrating an IT into the core-integration-tests

First, check out the core-integration-tests 

The sample project maps directly to the core-integration-tests structure. Assuming the test has been named uniquely, you can copy the contents of src/test directly over to core-integration-tests (don't copy from the root or you'll overwrite the pom). 

$ cp ../test/artifact/src . -R -v
`../test/artifact/src/test/java/org/apache/maven/integrationtests/' -> `./src/test/java/org/apache/maven/integrationtests/'
`../test/artifact/src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/pom.xml' -> `./src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/pom.xml'
`../test/artifact/src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/src/main/resources/rule_set.xml' -> `./src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/src/main/resources/rule_set.xml'
`../test/artifact/src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/src/main/resources/stc_checks.xml' -> `./src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/src/main/resources/stc_checks.xml'
`../test/artifact/src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/target/classes/rule_set.xml' -> `./src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/target/classes/rule_set.xml'
`../test/artifact/src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/target/classes/stc_checks.xml' -> `./src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-assembly/target/classes/stc_checks.xml'
`../test/artifact/src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-test/pom.xml' -> `./src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-test/pom.xml'
`../test/artifact/src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-test/src/main/java/' -> `./src/test/resources/mng-xxxx-descriptionOfProblem/checkstyle-test/src/main/java/'
`../test/artifact/src/test/resources/mng-xxxx-descriptionOfProblem/pom.xml' -> `./src/test/resources/mng-xxxx-descriptionOfProblem/pom.xml'
`../test/artifact/src/test/resources/mng-xxxx-descriptionOfProblem/readme.txt' -> `./src/test/resources/mng-xxxx-descriptionOfProblem/readme.txt'

Now add your test to the testSuite by adding a new line to "src\test\java\org\apache\maven\integrationtests\"

 suite.addTestSuite( MavenItmngXXXXDescriptionOfProblemTest.class );

Now run the suite:

Don't panic if some tests fail. That's probably normal. Only Panic if your test doesn't fail and it was supposed to (especially if you didn't write it).

Now add all those new files to svn (you can figure this one out on your own by're an expert...and its late here) and commit.

  • No labels