def "Spock 範例測試程式"() { given: def mockClass = Mock(ConcreteClass) def mockInterface1 = Mock(IInjection) IInjection mockInterface2 = Mock() Processor tester = new Processor(mockClass) mockInterface2.getInfo() >> { "二號測試字串" } when: tester.run(mockInterface1) then: 1 * mockClass.start() 1 * mockInterface1.getInfo() >> { "一號測試字串" } _ * mockClass.process(_) >> { mockInterface2 } 1 * mockInterface2.setData(_) 1 * mockClass.end() }