项目GitHub地址:https://github.com/Snowstorm0/learn-squaretest
项目Gitee地址:https://gitee.com/Snowstorm0/learn-squaretest
Squaretest是一款自动生成单元测试的插件,可以装在idea中。
打开idea,File——>Settings——>Plugins,搜索Squaretest,然后install就好了,插件安装完成后需要重启一下,如图所示:
首先我们在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:
即可生成单元测试文件:
解决一下单元测试中的报错即可。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。