学习spock测试框架

spock是一个单元测试框架,类似于junit,可以用java和groovy写。

依赖:

 <dependency>
            <groupId>org.spockframework</groupId> <artifactId>spock-core</artifactId> <version>1.2-groovy-2.4</version> <scope>test</scope> </dependency> <!-- Spock需要的groovy依赖 --> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>2.4.15</version> </dependency> <!-- spring boot spock --> <dependency> <groupId>org.spockframework</groupId> <artifactId>spock-spring</artifactId> <version>1.2-groovy-2.4</version> <scope>test</scope> </dependency>
测试方法的格式:

(1)given … expect … 格式:

given语句块为条件,expect为测试期望得到的结果,结果为true则通过测试。上面的示例就是这种格式的。

(2)given … when … then …

(3)when … then …

语义同上。

(4)given … expect … where …

(5)expect … where …

同上。

(6)expect …

扫描二维码关注公众号,回复: 8437875 查看本文章

同上。测试单个语句是否成立。

链接:

http://jvm123.com/2019/08/spock.html

https://www.jianshu.com/p/3ee99b8c6be1

猜你喜欢

转载自www.cnblogs.com/agnesFlower/p/12155946.html