How to use junit in intelliJ

本文介绍如何在IntelliJ IDE中使用JUnit进行单元测试,并展示如何计算测试覆盖率。首先创建Java程序及Triangle类,实现三角形类型的判断。接着引入JUnit和Hamcrest依赖,创建测试文件夹并配置为测试资源根目录。通过快捷键生成测试类,编写测试方法验证Triangle类的功能。最后运行测试并查看覆盖率报告。

My pages will tell you how to use unit test and test coverage in IntteliJ.

1.At first we need to create a java program.

2.create a class named Triangle and then right a method to 

calculates whether the triangle is equilateral, isosceles, or scalene.

3.add the junit and hamcrest jar package to the program

the intelliJ has the package in it lib

4. create a floder named TestTriangle and add root as a Test Sources Root

5. choose the Triangle class in editer,and use ctrl+shift+T to crate  a test class

6.write the test method to test the method in Triangle class.

7.to run the test we can click right point and choose Run"TriangleTest" or point Run

this is the result of the test

if we want to change run configurations we can by Run->Edit Configurations

8.the last is to use coverage test we can

use it by Run -> Run'TriangleTest'with coverage 

the result as follow

转载于:https://www.cnblogs.com/Bruce-Ge/p/6538932.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值