1.maven-surefire-plugin是个什么鬼? 如果你执行过mvn test或者执行其他maven命令时跑了测试用例,你就已经用过maven-surefire-plugin了。 maven-surefire-plugin是maven里执行测试用例的插件,不显示配置就会用默认配置。这个插件的surefire:test命令会默认绑定maven执行的test阶段。 的使用 如果说maven已经有了maven-surefire-plugin的默认配置,我们还有必要了解maven-surefire-plugin的配置么? [INFO] Surefire report directory: /Users/qyfmac/git/learn-maven/target/surefire-reports [INFO] Using /maven-surefire-plugin/xsd/surefire-test-report.xsd" name="com.qyf404.learn.maven.AppTest" time="0.001
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project Terminal执行命令 mvn install -Dmaven.test.skip=true 方法3:Spring boot项目使用 spring-boot-maven-plugin插件已经集成了maven-surefire-plugin
这个时候就需要 Maven 登场了,利用 Maven 的Maven-Surefire-Plugin插件可以帮助我们完成上述的目标!它可以通过命令行的形式来管理我们要执行的用例。 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin 抱歉,又要失望了,Google 到别人的解释如下(已翻译完成~): [image.png] 简单的说就是 surefire 插件暂时还不支持在 Junit5 下执行继承至 Junit4 的 @RunWith : <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId 七、写在最后 这里介绍了 maven-surefire-plugin 插件在测试执行中的一些常见用法,还有很多其他的用法,例如: 使用很复杂的格式匹配 控制在不同级别上的多线程和多进程执行 后续将慢慢研究补充
maven build时报错Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test [INFO could not be resolved: Failure to find org.apache.maven.surefire:maven-surefire-common:jar:2.12.4 in could not be resolved: Failure to find org.apache.maven.surefire:maven-surefire-common:jar:2.12.4 in could not be resolved: Failure to find org.apache.maven.surefire:maven-surefire-common:jar:2.12.4 in :2.12.4 or one of its dependencies could not be resolved: Failure to find org.apache.maven.surefire:maven-surefire-common
一般来说,我们会使用两个插件来一起完成单测覆盖率报告的生成,分别是: Maven Surefire Plugin JaCoCo Plugin 其中 Maven Surefire Plugin 是用来在 我根据这个文档(Maven Surefire Report Plugin – Usage)配置了一下 surefire-report 插件,成功地生成 HTML 格式的报告,如下图所示。 简单地说,Surefire 插件主要是运行单测,生成单测数据。对于 JaCoCo 插件而言,其作用是基于 Surefire 插件去生成可视化的报告。 JaCoCo 插件需要基于 Surefire 插件使用,如果去掉 Surefire 插件,JaCoCo 就生成不了报告了。 关于 Surefire 的一些配置不错!
:surefire-booter:jar:2.5 org.apache.maven.plugins:maven-surefire-plugin:jar:2.5 搜索方式 g:"org.apache.maven.plugins " AND a:"maven-surefire-plugin" AND v:"2.5" groupIP artifact version 4.安装jar包 mvn install:install-file :2.5:test': Unable to load the mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.5:test' in the plugin 'org.apache.maven.plugins:maven-surefire-plugin'. A required class is missing: org/apache/maven/surefire/util/NestedCheckedException org.apache.maven.surefire.util.NestedCheckedException
maven build时报错Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test [INFO could not be resolved: Failure to find org.apache.maven.surefire:maven-surefire-common:jar:2.12.4 in could not be resolved: Failure to find org.apache.maven.surefire:maven-surefire-common:jar:2.12.4 in could not be resolved: Failure to find org.apache.maven.surefire:maven-surefire-common:jar:2.12.4 in :2.12.4 or one of its dependencies could not be resolved: Failure to find org.apache.maven.surefire:maven-surefire-common
在使用surefire时,通过在pom.xml的插件标签中使用exclude元素和要排除的类的名称来排除一些测试类 2.1.跳过pom中的测试元素 如果您希望跳过某个项目的测试,您可以通过以下方式在项目的 skipTests 属性指定为 true: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin 大多数测试插件都支持这个属性,包括failsafe和surefire,甚至maven的编译器插件。 defaultValueOfSkip 的值设置为 false: 命令: mvn package -DdefaultValueOfSkip=false END 4.参考 http://maven.apache.org/surefire /maven-surefire-plugin/examples/skipping-tests.html https://www.educba.com/maven-skip-test/
surefire:test Run tests using Surefire. surefire:test Run tests using Surefire. :test' surefire:test Description: Run tests using Surefire. :2.12.4 Name: Maven Surefire Plugin Description: Surefire is a test framework project. surefire:test Run tests using Surefire.
></surefire.argLine> </properties> 添加属性,然后根据JDK的版本去添加对应的数据 2、使用属性 引入maven插件 <plugin> <groupId> org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>${ maven-surefire-plugin.version}</version> <configuration> <testFailureIgnore>true</testFailureIgnore -- 使用属性值来配置argLine --> <argLine>${surefire.argLine}</argLine> </configuration> </plugin> -- 重写argLine属性为Java 8+的配置 --> <surefire.argLine>--add-opens java.base/java.util=ALL-UNNAMED -
/maven2/org/apache/maven/plugins/maven- 16 surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.jar maven2/org/apache/maven/surefire/surefi 54 re-booter/2.12.4/surefire-booter-2.12.4.pom (3 KB at 6.2 surefire/surefi 58 re-api/2.12.4/surefire-api-2.12.4.pom (3 KB at 5.2 KB/sec) 59 Downloading: http: //repo.maven.apache.org/maven2/org/apache/maven/surefire/maven 60 -surefire-common/2.12.4/maven-surefire-common /maven2/org/apache/maven/surefire/maven 129 -surefire-common/2.12.4/maven-surefire-common-2.12.4.jar
-Dmaven.test.skip=true: 不执行测试用例,也不编译测试用例类 当然,还可以使用maven-surefire-plugin插件配置参数控制跳过单元测试。 plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin </configuration> </plugin> </plugins> </build> </project> 详见:http://maven.apache.org/surefire /maven-surefire-plugin/examples/skipping-tests.html
------------------------------------- [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin default-test) on project message-provider: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin MaxPermSize=256m -jar /opt/f/.m2/gitlab-runner/builds/0aa902b1/0/paas/message/message-provider/target/surefire /surefire1560965759779144679tmp /opt/f/.m2/gitlab-runner/builds/0aa902b1/0/paas/message/essage-provider /target/surefire/surefire_09112026330459044785tmp [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full
如果你执行过mvn test 或者执行其他maven命令时跑了测试用例,你就已经用过maven-surefire-plugin 了。 maven-surefire-plugin 是maven里执行测试用例的插件,不显示配置就会用默认配置。这个插件的surefire:test 命令会默认绑定maven执行的test 阶段。 <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test 在运行mvn install或mvn <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin 执行命令 mvn install -Dmaven.test.skip=true 方法四:Spring boot项目使用 spring-boot-maven-plugin插件已经集成了maven-surefire-plugin
sources指定扫描的目录, sourceEncoding指定扫描时的编码, java.binaries指定编译后的类文件目录(必填), java.test.binaries指定编译后的测试类目录,java.surefire.report Dsonar.java.binaries=target/classes \ -Dsonar.java.test.binaries=target/test-classes \ -Dsonar.java.surefire.report =target/surefire-reports 2. Dsonar.java.binaries=target/classes \ -Dsonar.java.test.binaries=target/test-classes -Dsonar.java.surefire.report =target/surefire-reports -Dsonar.branch.name=${branchName} -X """ } } 在Jenkinsfile中引用: 我们首先加载
解决的办法 在maven插件配置:(surefire2.14以下版本) <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId >maven-surefire-plugin</artifactId> <version>2.12</version> <configuration> <forkMode >always</forkMode> </configuration> </plugin> 重点加入configureation的配置部分 在maven插件配置:(surefire2.14及其以上版本 ) <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId 文件夹放在Class Path中,配置如下: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin
这插件是 maven-surefire-plugin—测试运行器。 默认情况下, maven-surefire-plugin 的 test 目标会自动执行测试源码路径(默认 src/test/java/)下所有符合一组命名模式的测试类如: **/Test*.java 插件提供该属性(一般不推荐): <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin 即使没有任何测试也不要报错,否侧maven-surefire-plugin找不到任何匹配的测试类,就会报错并导致构建失败; PS:上述命令行动态指定测试类的方法都应该只是临时使用,否则失去测试本身意义 maven 自动运行测试: <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId
可以在 Maven 的 <plugins> 标签中配置 Surefire Plugin 的 <parallel> 和 <threadCount> 属性来启用并行测试。 可以使用 Maven 的 Surefire Plugin 的 <includes> 和 <excludes> 属性来配置运行的测试范围。 可以在 Maven 的 <plugins> 标签中配置 Surefire Plugin 的 <parallel> 和 <threadCount> 属性来启用并行测试。 可以使用 Maven 的 Surefire Plugin 的 <includes> 和 <excludes> 属性来配置运行的测试范围。 可以使用 Maven 的 Surefire Plugin 的 <includes> 和 <excludes> 属性来配置运行的测试范围。 2.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test [ERROR] [ERROR] Please refer to E:\maven\web_nanchang\target\surefire-reports for the individual test <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin 8560d50788904ead0fbd9b7e0c1183&newp=81769a47889c1eed11bd9b7e0c1198231610db2151d3d51e218bcc0ada&user=baidu&fm=sc&query=maven-surefire-plugin