Spock Programmer : Setup / Cleanup Inheritance

Craig Atkinson's talk at GR8Conf US Intro to Spock and Geb claimed the next about Spock Cleanup / Inheritance.

Might have a hierarchy of test classes for DRY common test code Spock runs the base class setup first Then goes down the inheritance chain cleanup is the reverse, starting at test class then going up to base class I want it to double test to make sure I understood.

import spock.lang.Specification

abstract class BaseSpec extends Specification {
    def setup() { println 'base setup()' }
    def cleanup() { println 'base cleanup()' }

class DerivedSpec extends BaseSpec {
    def setup() { println 'derived setup()' }
    def cleanup() { println 'derived cleanup()' }

    def "test setup / cleanup inheritance"() {
        println "exectuting test case"

Running the above test prints:

base setup()
derived setup()
exectuting test case
derived cleanup()
base cleanup()

Really nice. Spock Setup / Cleanup inheritance to aid the creation of a hierarchy of tests classes.

Tags: #spock
Aug 2016, 21.


My next events:
🗓 Dec 12 16:00 Micronaut Essentials
🗓 Dec 13 16:00 Micronaut Essentials
🗓 Dec 14 16:00 Micronaut Essentials
🗓 Dec 15 16:00 Micronaut Essentials