如何配置pom以运行打包在jar中的测试? [英] How to configure pom to run tests packaged in a jar?

查看:102
本文介绍了如何配置pom以运行打包在jar中的测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven构建过程,该过程将可执行的jar及其测试发布到Nexus. 我有另一个Maven构建过程,需要访问这些jar(可执行+测试)并运行测试.

I have a maven build process that publishes executable jars and their tests to Nexus. I have another maven build process that needs to access these jars (executable + test) and run the tests.

我该怎么做?到目前为止,仅在jar分解为类文件时,我才设法做到这一点. 我是Maven新手,在文档中完全迷路了.

How do I go about it? So far I have managed to do this only if the jar is exploded to class files. I am new to maven and completely lost in the documentation.

推荐答案

Surefire和故障保护当前不支持从jar中运行测试.

Surefire and failsafe do not currently support running tests from within a jar.

在很大程度上是无法识别测试的情况.

This is largely a case of not being able to identify the tests.

有两种方法可以运行测试.

There are two ways to get the tests to run.

  1. 使用一个测试套件,其中列出了test-jar中的所有测试.因为测试套件将位于src/test/java中(更正确地将被编译为目标/测试类),所以它将被拾取,套件中的所有测试将由Surefire/failsafe运行(假定套件类名称)匹配包含规则:以测试"开始或结束)

  1. Use a test suite that lists all the tests from the test-jar. Because the test suite will be in src/test/java (more correctly will be compiled into target/test-classes) that will be picked up and all the tests in the suite will be run by Surefire/failsafe (assuming the suite class name matches the includes rule: starts or ends with Test)

使用maven依赖插件的unpack-dependencies目标将测试jar打包到目标/测试类中(这是骇人的声音,但效果很好)

Use the maven dependency plugin's unpack-dependencies goal to unpack the test-jar into target/test-classes (this screams of hack, but works quite well)

第一个选项的主要问题是,您不能轻易地从套件中仅运行一个测试,而需要从test-jar中命名每个测试

The main issue with the first option is that you cannot easily run just one test from the suite, and you need to name every test from the test-jar

因此,我倾向于选择选项2 ...选项2的另一个好处是,它并不意味着编写代码来解决构建工具插件中的限制.工具,更好的恕我直言

For that reason I tend to favour option 2... There is the added benefit that option 2 does not mean writing code to work around a limitation in a build tool plugin... The less you lock yourself into a specific build tool, the better IMHO

这篇关于如何配置pom以运行打包在jar中的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆