标签: maven-failsafe-plugin

maven-failsafe-plugin没有执行我的集成测试

贝娄我的实际pom的一部分.已经在@Test注释中为集成测试的Testng测试分配了一个"集成"组.为了做一点测试,我没有在测试阶段排除"集成"组.

使用例如mvn verify或mvn install进行构建时,集成测试将在测试阶段执行,但不会在验证阶段或集成测试阶段执行.测试的次数仍为0.不知怎的,它们没有被提取.任何人都知道什么可能是错的?

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12.1</version>
    <configuration>
      <skip>false</skip>
    </configuration>
  </plugin>
  <plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.12.1</version>
    <executions>
      <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>integration-test</goal>
        </goals>
        <configuration>
          <skip>false</skip>
          <excludedGroups>unit</excludedGroups>
        </configuration>
      </execution>
      <execution>
        <id>verify</id>
        <phase>verify</phase>
        <goals>
          <goal>verify</goal>
        </goals>
        <configuration>
          <skip>false</skip>
          <excludedGroups>unit</excludedGroups>
        </configuration>
      </execution>
    </executions>
    <configuration>
      <skip>false</skip>
      <excludedGroups>unit</excludedGroups>
    </configuration>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

更新:添加TestNG作为故障安全插件的依赖项没有帮助

integration testng maven maven-surefire-plugin maven-failsafe-plugin

2
推荐指数
1
解决办法
5515
查看次数

Maven Invoker插件与Maven Failsafe插件:哪个用于集成测试?

两者的文档(Failsafe,Invoker)表明它们对于运行集成测试很有用.我无法弄清楚哪一个用于集成测试.

我能看到的唯一区别是Failsafe插件专门用于运行集成测试,而Invoker插件恰好对运行集成测试很有用,但其主要目的是其他方面.但是,当我在Eclipse中创建maven-plugin时,Maven Invoker插件已经包含在POM文件中,并带有以下代码.

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-invoker-plugin</artifactId>
        <version>1.7</version>
        <configuration>
            <debug>true</debug>
            <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
            <pomIncludes>
                <pomInclude>*/pom.xml</pomInclude>
            </pomIncludes>
            <postBuildHookScript>verify</postBuildHookScript>
            <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
            <settingsFile>src/it/settings.xml</settingsFile>
            <goals>
                <goal>clean</goal>
                <goal>test-compile</goal>
            </goals>
        </configuration>
        <executions>
            <execution>
                <id>integration-test</id>
                <goals>
                    <goal>install</goal>
                    <goal>integration-test</goal>
                    <goal>verify</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>                 
Run Code Online (Sandbox Code Playgroud)

它们之间的主要区别是什么?是否存在特定情况,其中一个应优先于其他集成测试?

integration-testing maven-plugin maven maven-failsafe-plugin maven-invoker-plugin

2
推荐指数
1
解决办法
560
查看次数

如何在多模块Maven项目中运行集成测试

我有一个具有以下结构的多模块项目:

Project:    
 - module1
 - module2
 - integration-test
 - parent pom
Run Code Online (Sandbox Code Playgroud)

实现以下目标的正确方法是什么:

  • 使用以下命令从所有模块运行单元测试(集成测试除外) mvn clean install
  • 按需运行集成测试(可能是通过使用maven-failsafe插件还是通过maven概要文件?)
  • 集成测试失败时,构建失败。

一些注意事项:
-默认情况下,集成测试不应使用mvn clean install
-集成测试模块仅具有集成测试。

我已经尝试过使用maven-failsafe插件和maven-sunfire-plugin(用于单元测试)进行多次黑客攻击,但无法以标准方式实现上述目标。

以下是集成测试pom的相关部分的样子:

<dependencies>
   <!-- dependencies required for this module-->

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.12</version>
            <executions>
                <execution>
                    <id>add-integration-test-sources</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/test/java</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-integration-test-resources</id>
                    <phase>generate-test-resources</phase>
                    <goals>
                        <goal>add-test-resource</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <filtering>true</filtering>
                                <directory>src/test/resources</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin> 
    </plugins>
</build>

<profiles>
    <profile>
        <id>run-its</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId> …
Run Code Online (Sandbox Code Playgroud)

java maven-3 maven maven-failsafe-plugin

2
推荐指数
1
解决办法
2781
查看次数

如何在单个集成测试文件中控制测试执行的顺序?

我正在使用Maven 3.0.3,Failsafe插件v2.17和JUnit 4.11。目前,我有一个集成测试,测试顺序如下

@RunWith(SpringJUnit4ClassRunner.class)
public class MyTests {

    @Test
    public final void testAdd() {
        …
    }

    @Test
    public final void testUpdate() {
        …
    }

    @Test
    public final void testDelete() {
        …
    }
Run Code Online (Sandbox Code Playgroud)

目前,当我作为“ mvn全新安装”运行的一部分通过Maven运行测试时,在“ testAdd”或“ testUpdate”之前先运行“ testDelete”。如果我将名称更改为“ testZZZDelete”,那么它将最后运行,但我不喜欢这样。

如何使测试按照文件中指定的顺序运行?我的故障安全配置如下:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>2.17</version>
        <configuration>
                <reuseForks>true</reuseForks>
                <argLine>-Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
        </configuration>
        <executions>
                <execution>
                        <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                        </goals>
                </execution>
        </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

junit integration-testing maven maven-failsafe-plugin

1
推荐指数
1
解决办法
4667
查看次数

为什么failsafe: 不使用“mvn verify”执行?

为什么“failsafe:integration-test”不会自动执行mvn verify

根据mvn help:describe ...任务maven-failsafe-plugin“integraton-test”应该绑定到“integration-test”阶段:

failsafe:integration-test
  Description: Run integration tests using Surefire.
  Implementation: org.apache.maven.plugin.failsafe.IntegrationTestMojo
  Language: java
  Bound to phase: integration-test
Run Code Online (Sandbox Code Playgroud)

mvn verify只执行“surefire:test”,而不执行“failsafe:integration-test”。

我确实知道如何解决这个问题,<executions>因为即使在故障安全插件主页上的“用法”示例中也是如此,但我想了解为什么这两个插件的行为不同。

有匹配这两种<include>模式的文件:

src/test/java/de/lathspell/test/UselessThingTest.java
src/test/java/de/lathspell/test/UselessThingIT.java  
Run Code Online (Sandbox Code Playgroud)

我的 pom.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pom="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.lathspell</groupId>
    <artifactId>test1</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.22.1</version>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

输出:

[INFO] -------------------------< …
Run Code Online (Sandbox Code Playgroud)

maven maven-failsafe-plugin

0
推荐指数
1
解决办法
956
查看次数

Maven 故障安全系统属性变量

systemPropertyVariablesmaven-failsafe-plugin. 当集成测试在集成阶段运行时,systemPropertyVariables会正确拾取这些测试。

当我通过 IDE (IntelliJ) 运行单个测试时,它们systemPropertyVariables也会被拾取,但我不希望这样。

有没有办法在不使用 Maven 配置文件的情况下防止这种情况?

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <includes>
                        <include>**/*End2EndTest.java</include>
                    </includes>
                    <systemPropertyVariables>
                        <tomcat.host>host</tomcat.host>
                        <tomcat.port>8080</tomcat.port>
                        <tomcat.context>/</tomcat.context>
                        <tests.browser.name>chrome</tests.browser.name>
                        <tests.selenium.grid.address>http://localhost:4444/wd/hub/</tests.selenium.grid.address>
                        <spring.profiles.active>build</spring.profiles.active>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
     </build>
Run Code Online (Sandbox Code Playgroud)

提前致谢。问候

intellij-idea maven maven-failsafe-plugin

0
推荐指数
1
解决办法
1899
查看次数