Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何指定要测试的不同类名模式?_Java_Spring Boot_Testing - Fatal编程技术网

Java 如何指定要测试的不同类名模式?

Java 如何指定要测试的不同类名模式?,java,spring-boot,testing,Java,Spring Boot,Testing,我又要回到Java世界了 我正在学习教程(),当我使用mvn test运行测试时,HelloControllerIT中的所有测试都没有运行。似乎只考虑以“Test”结尾的类。我确信有一种方法可以添加额外的模式,从而包括HelloControllerIT 在哪里可以找到有关此主题的更多信息 这看起来很简单,所以我在搜索中可能没有使用正确的关键字(例如,“JavaSpring启动测试模式”) 更新 多亏了尤格·辛格的回答,我才想出了一个我觉得不错的解决方案。我把它添加到我的pom.xml文件中,现在

我又要回到Java世界了

我正在学习教程(),当我使用
mvn test
运行测试时,
HelloControllerIT
中的所有测试都没有运行。似乎只考虑以“Test”结尾的类。我确信有一种方法可以添加额外的模式,从而包括
HelloControllerIT

在哪里可以找到有关此主题的更多信息

这看起来很简单,所以我在搜索中可能没有使用正确的关键字(例如,“JavaSpring启动测试模式”)

更新

多亏了尤格·辛格的回答,我才想出了一个我觉得不错的解决方案。我把它添加到我的
pom.xml
文件中,现在我可以独立于集成测试运行单元测试

我忘记了个人资料

+    <profiles>
+        <profile>
+            <id>integration</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <includes>
+                                <include>**/*IT.java</include>
+                            </includes>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
运行集成测试

mvn test -Pintegration
参考(堆栈溢出):


您可以在pom.xml文件中尝试以下操作:

<build>
  <testSourceDirectory>src/main/java</testSourceDirectory>
  <plugins>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.16</version>
       <configuration>
          <includes>
             <include>**/*.java</include>
          </includes>
       </configuration>
    </plugin>
 </plugins>

src/main/java
org.apache.maven.plugins
maven surefire插件
2.16
**/*.爪哇

依我看,您应该只将测试放在测试包中,因为这是惯例。

请参阅以查看代码。
<build>
  <testSourceDirectory>src/main/java</testSourceDirectory>
  <plugins>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.16</version>
       <configuration>
          <includes>
             <include>**/*.java</include>
          </includes>
       </configuration>
    </plugin>
 </plugins>