java - Maven 使用关键字 "Test"运行所有测试

标签 java unit-testing maven selenium junit

我已经建立了一个带有 Junit 测试的 Maven 项目,以便在我们的构建服务器上运行 Selenium (java) 脚本。据我了解,Maven 旨在运行文件夹 test.java

中指定的任何文件

考虑到这一点,我使用 @RunWith@SuiteClasses 使用 TestAll 类设置了我的项目,以专门运行我想要的类和测试。

但是,当我运行 mvn test 时,maven 会运行标题中任意位置具有关键字 test 的所有方法,即 Test_A_1423、标题中带有“Test”的类中的所有测试以及任何标题中的所有内容。带有关键字“Test”的包。如何仅运行我想要的测试,或者我是否需要从我不想运行的任何类或方法中删除“测试”。包括我的 pom.xml 文件

`
 <modelVersion>4.0.0</modelVersion>
<groupId>cyberx.automation</groupId>
<artifactId>tests</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>cyberx.test.automation</name>
<url>http://maven.apache.org</url>
<!--<repositories>-->
    <!--<repository>-->
        <!--<id>central</id>-->
        <!--<name>bintray</name>-->
        <!--<url>http://jcenter.bintray.com</url>-->
    <!--</repository>-->
<!--</repositories>-->
<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
</dependency>
<dependency>
 <groupId>org.seleniumhq.selenium</groupId>
 <artifactId>selenium-java</artifactId>
 <version>2.45.0</version>
</dependency>
<dependency>
  <groupId>joda-time</groupId>
  <artifactId>joda-time</artifactId>
  <version>2.3</version>
 </dependency>
  <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.0.1</version>
   </dependency>
   <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
   </dependency>
   <!--<dependency>-->
      <!--<groupId>org.testng</groupId>-->
      <!--<artifactId>testng</artifactId>-->
      <!--<version>6.9.4</version>-->
      <!--<scope>test</scope>-->
   <!--</dependency>-->
   <dependency>
      <groupId>net.sf.opencsv</groupId>
      <artifactId>opencsv</artifactId>
      <version>2.3</version>
   </dependency>
  </dependencies>
  <build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
 </build>
 </project>
`

最佳答案

您有正则表达式来包含/排除测试。 请参阅here有关 Surefire 插件的文档。

关于java - Maven 使用关键字 "Test"运行所有测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30505906/

相关文章:

java - 自动调整位图图像的亮度、对比度和清晰度

java - 为什么我无法使用我的代码将 Excel 中的值放入列表中?

wpf - 寻找一些关于使用 MVVM 创建最佳实践单元测试的良好引用

java - maven项目执行失败 "maven-thrift-plugin"

java - 为 aspectj 运行 JDK8

java - 如何可视化 Stream 对象(以及其他一些数据类型)?

java - 过滤器中的自定义 propertyConverter 在 Neo4j OGM 中被覆盖

android - Jacoco 和 android-gradle-plugin >= 1.1 的单元测试代码覆盖率

java - 在 maven java 项目运行时获取激活的配置文件名称列表

Maven 依赖冲突 - 更高版本