我在TestNG中有很多测试套件.这些是XML文件.我希望能够在从maven运行集成测试时选择多个XML套件.
目前我可以将套件文件添加到pom.xml,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${pathToMySuiteFile_1}</suiteXmlFile>
<suiteXmlFile>${pathToMySuiteFile_1}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
该解决方案有一些局限性.我只能更改我在pom.xml中定义的测试套件的路径.所以在我的例子中,它总是必须是两个文件.我不能跑,比方说,5套房或只有一套.
有没有办法以某种方式参数化pom.xml中的整个"suiteXmlFiles"部分?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<suiteXmlFiles>
${multiple_paths_ToMySuiteFiles}
</suiteXmlFiles>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
运行与给定测试组匹配的所有内容对我来说不是一个选项:我不想加载我所拥有的所有套件,然后使用TestNG套件中的组运行所选的测试.原因是在运行具有组过滤器的所有测试套件之后生成的报告与仅运行所选测试套件时的报告不同.
我想配置maven sure fire插件来启动单元测试jvm和java代理的参数.代理jar文件是从maven中心获取的,所以我希望maven自动找出代理的jar文件的路径.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<argLine>-javaagent: How to reference an agent jar that is a depedency </argLine>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如何使用maven坐标来引用代理的路径,该代理是项目的依赖项?
为了管理/减少构建时间,我想确定哪些单元测试花费的时间最多 - 在并行测试环境中使用maven-surefire-plugin.
我们使用JUnit(4.10)进行单元测试.我们使用maven(2.2.1 - 我们使用的一些插件尚不支持maven 3)作为我们的主要构建工具,并使用maven-surefire-plugin(2.19)运行单元测试.
我们使用的是maven-surefire-plugin在并行模式,其中两个单独的方法在平行和单元测试类运行并行运行-这是非常重要的,因为它显著降低建设单位测试时间.的maven-surefire-plugin在构成.pom如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>-Xmx2G -XX:MaxPermSize=1G -XX:-UseSplitVerifier</argLine>
<failIfNoTests>false</failIfNoTests>
<parallel>classesAndMethods</parallel>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是,其中一个含义是在控制台输出中,每个JUnit测试类所用的时间是该类中所有方法的总时间.
例如,如果测试类有10个单元测试方法,每个测试方法需要1秒才能运行,那么测试类需要大约1秒才能运行(每个方法并行运行),但输出类似于:
运行com.package.QuickParallelTest测试运行:10,失败:0,错误:0,跳过:0,已过去时间:10.0秒 - 在com.package.QuickParallelTest中
这使得很难在控制台输出与另一个测试类中区分10个单元测试方法,其中9个几乎立即运行,1个运行几乎需要10秒.在这种情况下,测试类需要大约10秒才能运行(因为一个慢速测试方法),但maven-surefire-plugin控制台输出实际上是相同的:
运行com.package.SlowParallelTest测试运行:10,失败:0,错误:0,跳过:0,已过去时间:10.0秒 - 在com.package.SlowParallelTest
理想情况下,我希望花时间来指示测试类运行多长时间(并行),而不是单独运行方法所花费的总时间(就像单线程一样).
所以,我的问题是:
maven-surefire-plugin吗?(我检查了SureFire JIRA,但找不到这样的东西.)编辑:
我试过玩一些额外的配置设置.奇怪的是,将以下内容添加到配置中.pom似乎将控制台输出中经过的时间更改为运行测试类所花费的时间 - 但是,这(在我看来)这是违反直觉的,因为这些设置是默认设置:
<configuration>
...
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
</configuration>
Run Code Online (Sandbox Code Playgroud) 我想com.example.MyTest从命令行使用Maven构建项目时跳过单个测试(例如).
我知道像这样的类似问题,但它们都需要修改源代码或pom.xml.我想不做修改.如何仅使用命令行选项排除测试?
我在阅读一些文档后到目前为止所尝试的是
mvn clean install -Dtest="*,!com.example.MyTest"
Run Code Online (Sandbox Code Playgroud)
但测试仍然没有被跳过.我正在使用surefire插件版本2.19和JUnit 4.11.
我有一个大型项目,大约有5000个测试用例.在运行时mvn clean install,它将运行test目标两次(一次作为安装的一部分,第二次作为surefire插件的一部分).
为什么它需要test第二次运行?是否有力量surefire使用test目标结果而不是重新调用它自己?我认为这是浪费时间和机器资源,特别是最近第二轮运行test导致了一个PermGen构建错误,无论我用多少堆泵入maven runner,它仍然在第二轮测试中死亡.
这是我可靠的插入配置:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<parallel>classes</parallel>
<threadCount>3</threadCount>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
有没有办法调整插件以更好地处理机器资源?
以下是执行的完整默认maven配置文件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Build-Number>${build.number}</Build-Number>
<Job-Name>${job.name}</Job-Name>
<Build-Url>${build.url}</Build-Url>
<Git-Commit>${git.commit}</Git-Commit>
<Git-Branch>${git.branch}</Git-Branch>
<Timestamp>${maven.build.timestamp}</Timestamp>
<StyleGuide-Version>${styleguide.version}</StyleGuide-Version>
</manifestEntries>
</archive>
<warName>pss</warName>
</configuration>
</plugin>
<plugin>
<groupId>com.cj.jshintmojo</groupId>
<artifactId>jshint-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<goals>
<goal>lint</goal>
</goals>
</execution>
</executions>
<configuration>
<options>maxparams:5,camelcase,eqeqeq,forin,immed,latedef,noarg,noempty,nonew,expr</options>
<directories>
<directory>src/main/webapp/js/page</directory> …Run Code Online (Sandbox Code Playgroud) 我正在使用httpunit来访问服务器.
我需要为此配置代理设置(http和https).
我在settings.xml文件中设置了配置,但是确定似乎忽略了它!?
我想避免尽可能复制配置.
在surefire插件配置中我试过:
<systemPropertyVariables>
<http.proxyHost>${http.proxyHost}</http.proxyHost>
</systemPropertyVariables>
Run Code Online (Sandbox Code Playgroud)
和
<argLine>-Dhttp.proxyHost=${http.proxyHost}</argLine>
Run Code Online (Sandbox Code Playgroud)
和
<argLine>-Dhttp.proxyHost=${settings.proxies[protocol=http].host}</argLine>
Run Code Online (Sandbox Code Playgroud)
和其他几个组合.
我在单元测试中打印系统属性:
for (String propertyName : new TreeSet<String>(System.getProperties().stringPropertyNames())){
System.out.println(propertyName + ": " + System.getProperty(propertyName));
}
Run Code Online (Sandbox Code Playgroud)
到目前为止唯一有效的是显式值,例如:
<systemPropertyVariables>
<http.proxyHost>myProxy</http.proxyHost>
</systemPropertyVariables>
Run Code Online (Sandbox Code Playgroud)
要么
<argLine>-Dhttp.proxyHost=myProxy</argLine>
Run Code Online (Sandbox Code Playgroud)
但正如我所说,如果可能的话,我不想复制配置.
如何在单元测试中使用settings.xml文件中设置的代理设置?
我有几个测试用例,当整个测试运行只持续几秒钟时,JUnit会告诉我10000毫秒的时间.这是输出:
Tests run: 3, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 2.528 sec <<< FAILURE!
closeTest1(com.w2ogroup.analytics.sibyl.transport.impl.http.server.HttpServerTransportTests) Time elapsed: 1.654 sec <<< ERROR!
java.lang.Exception: test timed out after 10000 milliseconds
closeTest2(com.w2ogroup.analytics.sibyl.transport.impl.http.server.HttpServerTransportTests) Time elapsed: 0.672 sec <<< ERROR!
java.lang.Exception: test timed out after 50000 milliseconds
Results :
Tests in error:
HttpServerTransportTests » test timed out after 10000 milliseconds
HttpServerTransportTests » test timed out after 50000 milliseconds
Tests run: 3, Failures: 0, Errors: 2, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] …Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以argLine仅在<jdk.version>1.7</jdk.version>为 Java 1.7配置时才将此配置传递给 maven-surefire 插件, 而不能在用户更改pom.xml为 Java 1.8配置时传递给 maven-surefire 插件?
原因是 Java 1.8没有 permgen 空间。
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
Run Code Online (Sandbox Code Playgroud) dad给定一个带有模块和的 Maven 项目son,其中son依赖于dad,也mvn -am -pl son test运行测试dad。有没有办法避免这种情况并且只对son模块运行测试?
请注意,有几种方法可以实现此目的,尽管每种方法都有其自己的警告,但我不喜欢:
-Dtest="**/son/*Test.java" -DfailIfNoTests=false覆盖maven-surefire-plugin模块中的配置。-Dtest,JUnit 5 标签也可以被过滤,但这种方法也有前面提到的同样的缺点。install -DskipTests=true然后执行mvn -pl son test,尽管这会因部分工作而污染本地 Maven 存储库。当使用@Disabled* / @Enabled* 注释禁用测试时,这些测试将按预期跳过,但 Surefire 测试运行程序还会[WARNING]在受影响的类的结果行前面显示 。我的理解是,开发团队应该只看到需要进一步关注的事情的警告,因此我同意对某些测试(即由于未解决的错误而暂时禁用)发出警告可能是一件好事。
现在:我正在编写的测试套件涵盖了特定于不同操作系统环境 \xe2\x80\x93 的代码,例如,某些测试仅在 Windows 环境中运行时才有意义。因此,对此类测试发出警告是没有意义的(用@EnabledOnOs(OS.WINDOWS))发出警告是没有意义的,因为它们绝对没问题,并且预计会跳过(实际上是强制性的)\xe2\x80\x93,因此这里根本没有待办事项或问题。
我们如何控制哪些跳过的测试将导致警告(即通过@SuppressWarnings注释或某些万无一失的配置选项)?