testing con spock

19
TESTING CON SPOCK http://bitbucket.org/salenda/robot-cocina

Upload: fatima-casau

Post on 06-May-2015

480 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Testing con spock

TESTING CON SPOCK

http://bitbucket.org/salenda/robot-cocina

Page 2: Testing con spock

fatimacasau

Page 3: Testing con spock

TDD

AGILISMO

¡ESTÁN DE MODA!

ScrumKanban

XP

Page 4: Testing con spock

¿Test difíciles de comprender?

¿Test poco documentados?

¿Si los test fallan tardas en averiguar por qué?

¡Da pereza hacer tests!

Page 5: Testing con spock

¡¡Spock y Groovy son tus aliados!!

Page 6: Testing con spock

SPOCK• Framework para testing

• Altamente expresivo

• Groovy como lenguaje

• jUnit Runner

• Aplicaciones Java y Groovy

• Mock de objetos

Page 7: Testing con spock

Getting Started

• Spock Web Console - http://webconsole.spockframework.org

• Eclipse, IDEA, NetBeans

• Ant, Maven,Gradle

import spock.lang.*

class MyFirstSpecification extends Specification {

// fields

// fixture methods

// feature methods

// helper methods

}

Page 8: Testing con spock

FIELDS

def obj = new ClassUnderSpecification() def coll = new Collaborator()

@Shared res = new VeryExpensiveResource()

static final PI = 3.141592654

Page 9: Testing con spock

FIXTURE METHODS

def setup() {} // run before every feature method def cleanup() {} // run after every feature method def setupSpec() {} // run before the first feature method def cleanupSpec() {} // run after the last feature method

Page 10: Testing con spock

FEATURE METHODS

def "pushing an element on the stack"() { // blocks go here }

• Blocks

• Specification as Documentation

• Historias de usuario

Page 11: Testing con spock

BLOCKS

Page 12: Testing con spock

HELPER METHODS

• Otros métodos

• Llamados desde tests

• Reutilizar código

Page 13: Testing con spock

ETIQUETAS IMPORTANTES

• @Ignore

• @Unroll

@Unroll class DataDriven extends Specification { def "maximum of #a and #b is #c"() { expect: Math.max(a, b) == c where: a | b || c 3 | 5 || 5 7 | 0 || 7 0 | 0 || 0 } }

Page 14: Testing con spock

LOGS

maximum of 7 and 0 is 7 FAILED Math.max(a, b) == c | | | | | | 7 0 | 7 42 false

Page 15: Testing con spock

Contenido ExtraGrails y Test funcionales con Geb

Page 16: Testing con spock

GRAILS• Plugin Spock

• Tests unitarios (mocks)

• Dominio, Controllers, Constraints, Taglibs, Services...

• Tests integración

• Funcionales con apoyo de plugins

• Plugin Geb

Page 17: Testing con spock

GEB• Browser automation solution

• WebDriver

• jQuery content selection

• Page Object modelling

• Groovy language

• Spock testing

• The Book of Geb - http://www.gebish.org/manual/current/

• http://www.gebish.org/

Page 18: Testing con spock

import Geb.Browser Browser.drive { go "http://google.com/ncr" // make sure we actually got to the page assert title == "Google" // enter wikipedia into the search field $("input", name: "q").value("wikipedia") // wait for the change to results page to happen // (google updates the page dynamically without a new request) waitFor { title.endsWith("Google Search") } // is the first link to wikipedia? def firstLink = $("li.g", 0).find("a.l") assert firstLink.text() == "Wikipedia" // click the link firstLink.click() // wait for Google's javascript to redirect to Wikipedia waitFor { title == "Wikipedia" } }

GEB