12
Spock Abid H Khan

Spock

Embed Size (px)

Citation preview

Page 1: Spock

SpockAbid H Khan

Page 2: Spock

Agenda● Benefits of unit testing● Other testing framework● Spock Basics● Walkthrough

Page 3: Spock

Benefits of unit testing● Reduces bugs in production,reduces cost● Reduces development time● Increase confidence● can executes test cases frequently● Measures completion● Provides documentations● Improves design

Page 4: Spock

Other testing frameworks● JUnit● TestNG

Page 5: Spock

Spock Basics● Specification● Building blocks

o Fieldso Fixture methodso Feature methodso Helper methods

Page 6: Spock

Spock:Fields● Instance Fields

def pageNo=0def request = new GroupRequestDto()

● Shared Fields@Shared

@AutoCleanupRESTClient restClient

● Static Fieldsstatic final SUCCESS=200;

Page 7: Spock

Spock:Fixture methods● def setup() {} ● def cleanup() {} ● def setupSpec() {} ● def cleanupSpec() {}

Page 8: Spock

Spock:Feature methods● setup● when● then● expect● cleanup● where

Page 9: Spock

Vs JunitSpock Junit

Specification Test class

setup() @Before

cleanup() @After

setupSpec() @BeforeClass

cleanupSpec() @AfterClass

Feature Test

Parameterized feature Theory

Condition Assertion

Exception condition @Test(expected=...)

@FailsWith @Test(expected=...)

Interaction Mock expectation (EasyMock, JMock, ...)

Page 10: Spock

Walkthrough

Page 11: Spock

References● Spock Basics

https://code.google.com/p/spock/wiki/SpockBasics

● Benefits of Unit Testinghttp://sd.jtimothyking.com/2006/07/11/twelve-benefits-of-writing-

unit-tests-first/

Page 12: Spock