Intellij idea如何做单元测试 JUnit4
来源:互联网 发布:网络市场调研的5个步骤 编辑:程序博客网 时间:2024/06/05 16:49
1,新建maven工程-目录结构如下图:
2,在/src/main/java下新建 Maven3rd.java文件,代码如下:
/** * Created by sai on 17-7-31. */public class Maven3rd { public String sayHello(String name) { return "Hello," + name; }}3,添加测试。同时 按住 ctrl+shfit+T,然后,在弹窗选择 create New Test,然后出现下图:(选择JUnit4,选中 member),点击OK
4,打开 pom.xml文件,添加依赖:
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>test</scope> </dependency> </dependencies>5,在Maven3rdTest.java中导入
import org.junit.Test;/** * Created by sai on 17-7-31. */public class Maven3rdTest { @Test public void sayHello() throws Exception { Maven3rd m3 = new Maven3rd(); System.out.println(m3.sayHello("xiao")); }}
6,然后,点击左侧绿色三角就可以完成测试
7,在控制台,得到结果:
注意:添加依赖包的时候,不要选择 JUnit-4.11及以上版本,原因如下:
JUnit-4.11使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误
说明4.1.1中没有hamcrest包了,不知道作者是怎么想的。
最好的解决方法是:
1)换成junit-4.8.jar
2)junit-4.11.jar + hamcrest-core-1.3.jar
阅读全文
0 0
- Intellij idea如何做单元测试 JUnit4
- Intellij idea如何做单元测试 JUnit3
- intellij idea maven 工程junit4单元测试
- IntelliJ IDEA中如何使用JUnit4
- IntelliJ IDEA中如何使用JUnit4
- idea junit4 单元测试
- Idea配置JUnit4单元测试入门
- IntelliJ IDEA单元测试+SpringMvc单元测试
- IntelliJ IDEA单元测试入门
- IntelliJ IDEA单元测试入门
- IntelliJ IDEA单元测试入门
- JUnit单元测试--IntelliJ IDEA
- JUnit单元测试--IntelliJ IDEA
- JUnit单元测试--IntelliJ IDEA
- IntelliJ IDEA单元测试入门
- JUnit4结合spring做单元测试
- IntelliJ IDEA 逻辑层单元测试
- Junit4 with Intellij Idea and Maven
- 阅读Vue.jsAPI
- dp Vijos P1370 分苹果
- UVa12096(集合中的集合+stl)集合栈计算机
- 数据库SQL实战
- 【CodeForces】426Div2 C The Meaningless Game
- Intellij idea如何做单元测试 JUnit4
- 使用Markdown编辑器写博客
- linux下源码包安装nginx
- 回车按钮绑定事件
- 嵌入式软件调试方法 【转载+补充】
- log4j配置信息详解
- get与post区别
- 结构体大小的计算及设置内存字节对齐数原理理解
- get请求受Tomcat编码影响导致乱码