maven安装junit_JUnit安装Maven – JUnit 4和JUnit 5
maven安装junit
JUnit 4 and JUnit 5 are completely different frameworks. They both serve the same purpose, but the JUnit 5 is a completely different testing framework written from scratch. It’s not using anything from JUnit 4 APIs.
JUnit 4和JUnit 5是完全不同的框架。 它们的目的相同,但是JUnit 5是完全不同的测试框架。 它没有使用JUnit 4 API中的任何东西。
Here we will look into how to setup JUnit 4 and JUnit 5 in our maven projects.
在这里,我们将研究如何在maven项目中设置JUnit 4和JUnit 5 。
JUnit Maven依赖关系 (JUnit Maven Dependencies)
If you want to use JUnit 4, then you need a single dependency as below.
如果要使用JUnit 4,则需要一个依赖项,如下所示。
<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope>
</dependency>
JUnit 5 is divided into several modules, you need at least JUnit Platform and JUnit Jupiter to write tests in JUnit 5. Also, note that JUnit 5 requires Java 8 or higher versions.
JUnit 5分为几个模块,您至少需要JUnit Platform和JUnit Jupiter才能在JUnit 5中编写测试。此外,请注意,JUnit 5需要Java 8或更高版本。
<dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-engine</artifactId><version>5.2.0</version><scope>test</scope>
</dependency>
<dependency><groupId>org.junit.platform</groupId><artifactId>junit-platform-runner</artifactId><version>1.2.0</version><scope>test</scope>
</dependency>
If you want to run parameterized tests, then you need to add an additional dependency.
如果要运行参数化测试 ,则需要添加其他依赖项。
<dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-params</artifactId><version>5.2.0</version><scope>test</scope>
</dependency>
Maven构建期间的JUnit测试 (JUnit Tests During Maven Build)
If you want the tests to be executed during the maven build, you will have to configure maven-surefire-plugin
plugin in your pom.xml file.
如果要在maven构建期间执行测试,则必须在pom.xml文件中配置maven-surefire-plugin
插件。
JUnit 4:
JUnit 4 :
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.22.0</version><dependencies><dependency><groupId>org.apache.maven.surefire</groupId><artifactId>surefire-junit4</artifactId><version>2.22.0</version></dependency></dependencies><configuration><includes><include>**/*.java</include></includes></configuration></plugin></plugins>
</build>
JUnit 5:
JUnit 5 :
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>2.22.0</version><dependencies><dependency><groupId>org.junit.platform</groupId><artifactId>junit-platform-surefire-provider</artifactId><version>1.2.0</version></dependency></dependencies><configuration><additionalClasspathElements><additionalClasspathElement>src/test/java/</additionalClasspathElement></additionalClasspathElements></configuration></plugin></plugins>
</build>
JUnit HTML报告 (JUnit HTML Reports)
Maven surefire plugin generates text and XML reports, we can generate HTML based reports using maven-surefire-report-plugin
. Below configuration works for both JUnit 4 and JUnit 5.
Maven surefire插件生成文本和XML报告,我们可以使用maven-surefire-report-plugin
生成基于HTML的报告。 以下配置适用于JUnit 4和JUnit 5。
<reporting><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-report-plugin</artifactId><version>2.22.0</version></plugin></plugins>
</reporting>
Just run mvn site
command and the HTML report will be generated in the target/site/
directory.
只需运行mvn site
命令,HTML报告将在target/site/
目录中生成。
That’s all for a quick roundup of JUnit setup for maven projects.
这就是为Maven项目快速汇总JUnit设置的全部内容。
翻译自: https://www.journaldev.com/21711/junit-setup-maven
maven安装junit
maven安装junit_JUnit安装Maven – JUnit 4和JUnit 5相关推荐
- maven开发工具安装
Maven安装并测试步骤: 1.下载并解压meaven.zip: 2.配置环境变量"M2_HOME"指向meaven安装目录: 3.添加"%M2_HOME%\bin;&q ...
- nexus-3.6.0-02-unix.tar.gz安装(Centos下),maven setting.xml配置案例,项目root的pom.xml配置,parent-pom的pom.xml配置案例
1.下载nexus 进入:http://www.sonatype.org/nexus/downloads/ 说明: [OSS = Open Source Software,开源软件 – 免费] [FR ...
- 5.Maven和Eclipse整合(两种方式进行插件的安装),Maven相关设置,Eclipse下创建Maven项目
1 第一种方式是:在连网的情况下,通过在helpàInstall下安装. 新的地址是:http://download.eclipse.org/technology/m2e/releases 2 ...
- maven安装教程安装教程_Maven教程之春
maven安装教程安装教程 1.简介 在这篇文章中,我们将演示如何针对非常特定的用例对Spring使用Maven依赖项. 我们使用的所有库的最新版本都可以在Maven Central上找到. 对于一个 ...
- 手把手maven的功能/安装/使用/idea集成
看这篇文章不用着急安装,跟着步骤一定会成功,要理解maven是什么,如何使用. 介绍 maven官网 对于一个小白来说,官网有用的信息就是这些 不管如何介绍maven,作为使用者来说,主要感觉两个方面 ...
- centos7 yum安装maven_Linux安装tomcat、mysql 、Maven与Eclipse的整合、settings.xml
第145次(Linux) 学习主题:Linux 学习目标: 掌握Linux安装管理tomcat与mysql 一.Linux软件安装-安装tomcat 在Linux系统中如何启动tomcat? 1.进入 ...
- Java入门基础(十四)Maven仓库的安装
文章目录 一.下载配置Maven环境 1.下载maven.jar解压缩,放在一个文件夹下 2.点击此电脑=>属性=>高级设置=>环境变量=>系统变量=>新建 3.变量名为 ...
- Maven学习以及安装配置教程
Maven学习以及安装配置教程 一.简介 Maven是Apache软件基金会推出用于java项目构建以及依赖管理的工具 官方网站:Maven Repository: commons-httpclien ...
- Mac安装和配置Maven
Mac安装和配置Maven 狂神说Java 1.安装 在官网下载maven:maven官网 下载完成后解压文件到资源库(我是放到资源库) 2.配置环境变量 打开终端输入 vi ~/.bash_prof ...
最新文章
- SRCNN-图像超分辨的学习
- 怎么用python判断数据是否已经存在于表里_数据基本操作(二)
- npjsba-2018-用肠道微生物模型指导个性化膳食缓解局部性肠炎
- executequery方法_【接口测试】soapui中数字、字符串、日期时间、数据库连接参数化的设置方法...
- collection包下Counter类统计list中各个元素出现的次数
- thymeleaf报错:Could not load content for xxx /css/bootstrap.min.css.map:HTTP error: status
- JVM-Java程序性能监控-初级篇
- glide工具类。加载显示原图片,显示圆角图片,gif图标显示
- 3、C#面向对象:封装、继承、多态、String、集合、文件(下)
- 常见Serialize技术探秘(ObjectXXStream、XML、JSON、JDBC byte编码、Protobuf)
- python中凯撒密码加密_凯撒密码加密
- 移动互联网实时视频通讯之视频采集
- win10好用的小软件(小插件)
- 值传递,指针传递,引用传递的区别
- OBS studio
- 嵌入式Linux系统环境搭建全流程-4412友善之臂开发板
- ssh 远程报错 Permission denied, please try again.(密码输入正确也无法登录)
- Java进阶(四)多态
- linux 脚本 $? -ne 0是什么意思,【shell】linux之if [ $? -ne 0 ];-ne 表示 不等于,参考shell中运算符整数比较
- git remote add origin xxx.git 的问题解决
热门文章
- metasploit连接postgresql的问题(U盘启动kali linux)
- vs2010上opencv配置
- VMware vSphere Hypervisor下载
- unrecognized selector sent to instance
- base,override,virtual
- [转载] 使用Keras和TensorFlow 2.0建立深度学习模型对图像进行分类
- [转载] Python之NumPy基础:数组与向量化计算
- [转载] numpy.bincount介绍以及巧妙计算分类结果中每一类预测正确的个数
- Java匹马行天下之学编程的起点——编程常识知多少
- CentOS 7 配置网络连接