项目GitHub地址:https://github.com/Snowstorm0/learn-squaretest
项目Gitee地址:https://gitee.com/Snowstorm0/learn-squaretest
Squaretest是一款自动生成单元测试的插件,可以装在idea中。
1.安装插件
打开idea,File——>Settings——>Plugins,搜索Squaretest,然后install就好了,插件安装完成后需要重启一下,如图所示:
2 生成单测
首先我们在src
目录下面新建test
目录,并将其设置为单元测试的目录:
在pom文件添加单元测试的依赖:
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.19.0</version>
<scope>test</scope>
</dependency>
打开一个类,这个类就是我们即将要作为实验的类,打开你的类,光标定位到代码里,右击鼠标选择Generate…
:
然后选择Generate Test
:
选择“Test language”、“Template”、“Test Sources Root”,然后点OK:
即可生成单元测试文件:
解决一下单元测试中的报错即可。
学习更多编程知识,请关注我的公众号:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。