相关疑难解决方法(0)

如何在maven中的集成测试目标中运行单个测试

我们为maven中的集成测试阶段生命周期定义了数百个测试,并且需要很长时间才能完成.

我想要做的只是运行一个测试integration-test.我试过做:

mvn -Dtest=<my-test> integration-test
Run Code Online (Sandbox Code Playgroud)

但这不起作用.将-Dtest只运行在单元测试目标测试,而不是集成测试阶段.我试过了-Dintegration-test=<my-test>,但是被忽略了.

有没有办法做到这一点 ?


我的配置是:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <executions> 
        <execution> 
            <id>surefire-it</id> 
            <phase>integration-test</phase> 
            <goals> 
                <goal>test</goal> 
            </goals> 
            <configuration> 
                <excludes> 
                    <exclude>none</exclude> 
                </excludes> 
                <includes>
                    <include>**/api/**</include> 
                </includes> 
    ..... 
Run Code Online (Sandbox Code Playgroud)

integration-testing maven-2 maven-surefire-plugin

42
推荐指数
4
解决办法
3万
查看次数

如何获取命令行属性来覆盖maven属性

我有一个pom文件,其中一些依赖项的版本号依赖于pom文件的设置中指定的项目版本属性.我可以通过命令行覆盖它吗?如果是这样,怎么样?

这是长篇故事:

我们目前正在将我们的项目转移到maven,但我们还没有完成任何方式.有多个模块仍然没有使用maven构建,因此是我们项目中的依赖项(它们通过ant构建到jar中).发布后,我们希望构建所有这些jar并包含与父项目相同的版本号.对于发布,执行两个步骤(直到我们可以使用maven获取所有内容)

  1. 这些罐子是用正确的发布版本(12.12.4.0)构建的.
  2. maven发布插件用于将项目部署到我们的工件库.

在第二步中,命令行参数用于指定发行版:

mvn release:prepare -DreleaseVersion=12.12.4.0 -DdevelopmentVersion=12.12.4.1-SNAPSHOT -Dtag=iv-12.12.4.0
Run Code Online (Sandbox Code Playgroud)

我想用指定的版本更新pom文件.但是,运行此命令时,仍在使用pom文件(12.12.4.0-SNAPSHOT)中的版本.这无法"检查快照的依赖项和插件"步骤,我需要解析仍然具有maven版本属性使用的12.12.4.0-SNAPSHOT版本的jar.

这让我想到了如何覆盖它的原始问题,以便版本解析为命令行中指定的版本.可以让我解决的其他问题是:如何在此检查之前允许maven发布插件更新pom文件?如何跳过快照检查(不可取)

我可以在pom文件中创建一个我可以覆盖的属性,但是我必须在pom文件中的两个位置维护版本号.

思考?

maven maven-release-plugin

19
推荐指数
1
解决办法
3万
查看次数

maven-surefire插件中的"默认测试"代表什么?

我在我的pom中使用TestNg确定了以下配置:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12</version>
            <configuration>
                <skipTests>${skip-all-tests}</skipTests>
            </configuration>
            <executions>
                <execution>
                    <id>unit-tests</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>${skip-unit-tests}</skip>
                        <groups>unit</groups>

                        <excludedGroups>integration</excludedGroups>
                    </configuration>
                </execution>
                <execution>
                    <id>integration-tests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>${skip-integration-tests}</skip>
                        <groups>integration</groups>
                        <excludedGroups>unit</excludedGroups>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

但似乎两次执行总是先于"默认测试"运行,它似乎运行每个@test注释方法(至少我认为是这样).

--- maven-surefire-plugin:2.12:test (default-test) @ my-project
Run Code Online (Sandbox Code Playgroud)

例如,在项目上运行"mvn test",就会发生两次测试."默认测试"和"单元测试".

有人可以向我解释一下吗?这可以被禁用或控制(配置什么是测试的,什么不是)?

testng maven-3 maven-surefire-plugin

8
推荐指数
2
解决办法
8386
查看次数

如何使用Maven在Spring Boot中仅执行集成测试

我试图通过maven命令分离单元测试和集成测试。

pom.xml

....

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*Fast*</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
Run Code Online (Sandbox Code Playgroud)

这是我的整合测试

@RunWith(SpringRunner.class)
@SpringBootTest(classes = StudentApplication.class,
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class StudentControllerIT {

...
Run Code Online (Sandbox Code Playgroud)

这是单元测试

@RunWith(SpringRunner.class)
@WebMvcTest(value = StudentController.class, secure = false)
public class StudentFastControllerTest {

....
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试运行命令时,mvn testStudentFastControllerTest执行测试,但是当我运行命令mvn integration-testmvn verify同时执行两个测试类而不是仅执行时StudentControllerIT

junit4 maven maven-failsafe-plugin spring-boot

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

如何在多模块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
查看次数