Testing con spock

994 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
994
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Testing con spock

  1. 1. TESTING CON SPOCKhttp://bitbucket.org/salenda/robot-cocina
  2. 2. fatimacasau
  3. 3. AGILISMO Scrum XP Kanban TDD¡ESTÁN DE MODA!
  4. 4. ¿Test difíciles de comprender? ¿Test poco documentados?¿Si los test fallan tardas en averiguar por qué? ¡Da pereza hacer tests!
  5. 5. ¡¡Spock y Groovy son tus aliados!!
  6. 6. SPOCK• Framework para testing• Altamente expresivo• Groovy como lenguaje• jUnit Runner• Aplicaciones Java y Groovy• Mock de objetos
  7. 7. Getting Started• Spock Web Console - http://webconsole.spockframework.org• Eclipse, IDEA, NetBeans import spock.lang.*• Ant, Maven,Gradle class MyFirstSpecification extends Specification { // fields // fixture methods // feature methods // helper methods }
  8. 8. FIELDSdef obj = new ClassUnderSpecification()def coll = new Collaborator()@Shared res = new VeryExpensiveResource()static final PI = 3.141592654
  9. 9. FIXTURE METHODSdef setup() {} // run before every feature methoddef cleanup() {} // run after every feature methoddef setupSpec() {} // run before the first feature methoddef cleanupSpec() {} // run after the last feature method
  10. 10. FEATURE METHODS def "pushing an element on the stack"() { // blocks go here } • Blocks • Specification as Documentation • Historias de usuario
  11. 11. BLOCKS
  12. 12. HELPER METHODS • Otros métodos • Llamados desde tests • Reutilizar código
  13. 13. 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 } }
  14. 14. LOGSmaximum of 7 and 0 is 7 FAILEDMath.max(a, b) == c | | | | | | 7 0 | 7 42 false
  15. 15. Contenido Extra Grails y Test funcionales con Geb
  16. 16. GRAILS• Plugin Spock• Tests unitarios (mocks) • Dominio, Controllers, Constraints, Taglibs, Services...• Tests integración • Funcionales con apoyo de plugins • Plugin Geb
  17. 17. 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/
  18. 18. GEBimport Geb.BrowserBrowser.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 Googles javascript to redirect to Wikipedia waitFor { title == "Wikipedia" }}

×