☰
26、Spock单元测试:从基础到应用
2026/10/17 5:52:49 网站建设 项目流程

Spock单元测试:从基础到应用

一、Spock测试块的使用

1.1 使用and:块拆分when:块

在Spock测试中,when:块可以被拆分,通过and:块来实现。以下是一个示例:

def "A basket with three products weights as their sum (alternate)"() { given: "an empty basket, a TV,a camera and a hifi" Basket basket = new Basket() Product tv = new Product(name:"bravia",price:1200,weight:18) Product camera = new Product(name:"panasonic",price:350,weight:2) Product hifi = new Product(name:"jvc",price:600,weight:5) when: "user wants to buy the TV.." basket.addProduct tv and: "..the camera.." basket.addProduct camera and: "..and the wifi"

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询