Maven: Как настроить тесты для запуска в фазе интеграционных тестов? - PullRequest
2 голосов
/ 28 ноября 2011

Я использую Maven 3.0.3.Я хочу выполнить некоторые тесты Junit на этапе тестирования, а другие - на этапе тестирования интеграции.Проблема в том, что на этапе тестирования интеграции ничего не работаетЯ запускаю команду

mvn clean install

, чтобы начать все.Вот как я настроил свой плагин surefire ...

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <skip>false</skip>
                <additionalClasspathElements>
                    <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
                    <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
                </additionalClasspathElements>
                <useManifestOnlyJar>false</useManifestOnlyJar>
                <forkMode>always</forkMode>
                <systemProperties>
                    <property>
                        <name>gwt.args</name>
                        <value>-out \${webAppDirectory}</value>
                    </property>
                </systemProperties>
                <excludes>
                    <exclude>**/integration/**</exclude>
                </excludes> 
            </configuration>
            <executions>
                <execution>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                        <includes>
                            <include>**/integration/**</include>
                        </includes> 
                    </configuration>
                </execution>
            </executions>
        </plugin>

У меня есть два теста JUnit в моей директории "интеграции".Я использую плагин Maven Cargo для раскрутки сервера на этапе интеграции.Вот эта конфигурация ...

        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <configuration>
                <container>
                    <containerId>tomcat${tomcat.major}x</containerId>
                    <zipUrlInstaller>
                        <url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
                        <downloadDir>${project.build.directory}/downloads</downloadDir>
                        <extractDir>${project.build.directory}/extracts</extractDir>
                    </zipUrlInstaller>
                    <output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
                    <log>${project.build.directory}/cargo.log</log>
                </container>
                <configuration>
                    <home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
                    <properties>
                        <cargo.logging>high</cargo.logging>
                        <cargo.servlet.port>${tomcat.servlet.port}</cargo.servlet.port>
                        <cargo.tomcat.ajp.port>${tomcat.ajb.port}</cargo.tomcat.ajp.port>
                    </properties>
                </configuration>
            </configuration>
            <executions>
                <execution>
                    <id>start-container</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start</goal>
                        <goal>deploy</goal>
                    </goals>
                    <configuration>
                        <deployer>
                            <deployables>
                                <deployable>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>${project.artifactId}</artifactId>
                                    <type>war</type>
                                    <pingURL>http://localhost:${tomcat.servlet.port}/${project.artifactId}</pingURL>
                                    <pingTimeout>30000</pingTimeout>
                                    <properties>
                                        <context>${project.artifactId}</context>
                                    </properties>
                                </deployable>
                            </deployables>
                        </deployer>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-container</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Есть идеи, как изменить / улучшить мою конфигурацию, чтобы мои интеграционные тесты работали?- Дэйв

1 Ответ

2 голосов
/ 28 ноября 2011

Взгляните на Плагин Maven Failsafe

...