标签: surefire

从classpath运行maven测试

为了清理一个巨大的烂摊子的事,我开始把我的测试代码都在一个普通的Java项目(所有的src/main/JAVA),然后声明,作为一个<scope>test</scope>在另一个项目的依赖,并期待要运行的测试.

没有这样的运气.surefire想要运行它可以在源代码中看到的测试.

我可以看到一个可悲的是显而易见的解决方案在这里涉及构建辅助性插件,并添加测试到测试编译环境为源目录,但我希望避免它.

如果你想知道,这一切的原因是,使用故障安全插件的运行一些集成测试的POM的配置有这么复杂,我想从测试的运行打出了测试类的编译.

maven-2 surefire

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

从Maven中排除TestNG组

我有一些慢速测试依赖于我不希望每次使用Maven构建项目时都运行的数据库.我已经将excludedGroups元素添加到我的pom文件中,如http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html#excludedGroups所述,但我似乎无法使其正常工作.

我创建了一个最小的项目.这是pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>exclude</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.4.2</version>
                <configuration>
                    <excludedGroups>db</excludedGroups>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>5.14</version>
        </dependency>
    </dependencies>

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

这些是两个测试类:

public class NormalTest {

    @Test
    public void fastTest() {
        Assert.assertTrue(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

public class DatabaseTest {

    @Test(groups={"db"})
    public void slowTest() {
        Assert.assertTrue(false);
    }
}
Run Code Online (Sandbox Code Playgroud)

然而,两个测试仍然运行.我无法弄清楚我做错了什么.

testng surefire maven

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

Surefire按顺序运行某些测试,其他并行运行

有没有办法让某些测试与JUnit的surefire插件一起按顺序运行?当前,它正在并行运行所有测试,但是有些测试很难转换,如果不并行运行就足够了。这是我们pom.xml的一部分:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.17</version>
    <dependencies>
      <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit47</artifactId>
        <version>2.17</version>
      </dependency>
    </dependencies>
    <configuration>
        <parallel>all</parallel>
        <threadCount>8</threadCount>
      <includes>
        <include>${includeTest}</include>
        <include>${includeAdditionalTest}</include>
      </includes>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

java automated-tests test-suite surefire pom.xml

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

使用Maven Surefire插件可以多次运行相同的测试吗?

有一个配置值rerunFailingTestsCount,但是即使它成功,我也想以可配置的次数运行测试方法。有什么选择吗?

java junit4 maven-plugin surefire maven-3

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

Maven surefire forkMode pertest已弃用.什么是新设置?

从Surefire 2.14开始,forkMode配置设置已被弃用.他们甚至可以帮助提供从一些旧设置到新设置的映射(http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html).

我们使用的问题是<forkMode>pertest</forkMode>该页面上没有映射,而我的google-fu无法找到适当的更新配置.

什么是适当的forkCount,reuseForks,parallel和/或其他配置,以取代已弃用的forkMode=pertest设置?

java automated-tests surefire maven maven-surefire-plugin

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

JUnit运行器从java.io.Writer获取NullPointerException


我从Maven Surefire插件获得NullPointerException.它仅在使用DBUnit的测试中发生.Surefire报告文件为空.

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
org.apache.maven.surefire.booter.SurefireExecutionException: null; nested exception is java.lang.NullPointerException: null
java.lang.NullPointerException
    at java.io.Writer.write(Writer.java:140)
    at java.io.PrintWriter.newLine(PrintWriter.java:436)
    at java.io.PrintWriter.println(PrintWriter.java:585)
    at java.io.PrintWriter.println(PrintWriter.java:696)
    at org.apache.maven.surefire.report.AbstractFileReporter.testSetStarting(AbstractFileReporter.java:59)
    at org.apache.maven.surefire.report.ReporterManager.testSetStarting(ReporterManager.java:219)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
Run Code Online (Sandbox Code Playgroud)

当我尝试使用JUnit运行程序从NetBeans IDE运行相同的测试时,我得到相同的异常:

Exception in thread "main" java.lang.NullPointerException
        at java.io.Writer.write(Writer.java:140)
        at org.apache.tools.ant.util.DOMElementWriter.write(DOMElementWriter.java:212)
        at org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.endTestSuite(XMLJUnitResultFormatter.java:171)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.fireEndTestSuite(JUnitTestRunner.java:714)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:547)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1031)
        at …
Run Code Online (Sandbox Code Playgroud)

java junit surefire

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

通过maven2显示junit失败消息

我有一个通过maven2构建的Java项目.我们使用JUnits并偶尔会出现测试失败.我想知道在测试失败时是否有办法显示更多信息.当我通过IntelliJ运行测试时,我会得到类似"预期:3实际:10"的内容.

有没有办法通过maven获取相同的数据?

junit maven-2 surefire

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

如何在Maven中运行单独的测试?

我们正在使用Maven 3.0.3并使用JUnit 4.8.1 ...

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

我们有这个测试文件......

./src/test/java/com/myco/clearing/common/xml/TextNodeTest.java
Run Code Online (Sandbox Code Playgroud)

我怎样才能运行这个单独的测试?当我尝试

mvn -Dtest=TextNodeTest test
Run Code Online (Sandbox Code Playgroud)

我得到一个错误,说没有运行测试.如果我将整个包名称指定给我的测试,我会得到相同的错误....

mvn clean -Dtest=com.myco.clearing.common.xml.TextNodeTest test
Run Code Online (Sandbox Code Playgroud)

产生错误信息......

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project myco-productplus-web: No tests were executed!
(Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about …
Run Code Online (Sandbox Code Playgroud)

junit surefire maven

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

使用带有 maven surefire 插件的自定义报告器

我正在尝试使用带有 maven surefire 插件的 TestNG 自定义报告器。我已经有一个自定义的侦听器,并且似乎被接受了。但是,看起来根本没有使用自定义报告器:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <testFailureIgnore>false</testFailureIgnore>
        <properties>
            <property>
                <name>listener</name>
                <value>com.mystuff.test.TestNGListener</value>
            </property>
            <property>
                <name>reporter</name>
                <value>com.mystuff.test.MyEmailableReporter</value>
            </property>
        </properties>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?

testng surefire maven

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

无法删除surefirebooster

我在 Windows 10 系统上使用 Eclipse 工作区(版本:Mars Release (4.5.0) Build id:20150621-1200)。在我签出一个项目并尝试使用 Maven clean 构建它之后,它会导致构建失败。这是我得到的错误

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building XYZ:: SU 2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] Downloading: https://XYZ/maven-resources-plugin/maven-metadata.xml
[INFO] Downloading: https://XYZ/maven-jar-plugin/maven-metadata.xml
[INFO] Downloading: https://XYZ/maven-install-plugin/maven-metadata.xml
[INFO] Downloading: https://XYZ/maven-metadata.xml
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ geodis-su ---
[INFO] Deleting C:\Users\Documents\workspace\XYZ\XYZ-su\target
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.300 s
[INFO] Finished at: 2016-05-17T14:35:56+02:00
[INFO] Final Memory: 18M/284M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project geodis-su: …
Run Code Online (Sandbox Code Playgroud)

eclipse surefire maven maven-surefire-plugin eclipse-mars

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

使用不同的参数两次执行Maven-surefire-plugin

我正在尝试通过带有两个不同参数的sure-fire插件运行我的单元测试。一种是使用jacoco将测试结果输入SonarQube,另一种是使用dynatrace运行。我尝试将其放在两个不同的执行标签中,但似乎无法正常工作。请问我做错了什么?以下是我的pom.xml的片段:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.12</version>
  <configuration>
     <argLine>${jacoco.ut.arg}</argLine>
     <argLine>-agentpath:"C:\Program Files\dynaTrace\Dynatrace 6.3\agent\lib64\dtagent.dll"=name=JavaAgent,server=localhost:9998,optionTestRunIdJava=${dtTestrunID}</argLine>
     <excludes>
       <exclude>**/at/**</exclude>
       <exclude>**/it/**</exclude>
     </excludes>
   </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

unit-testing surefire maven

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