8. FIELDS
def obj = new ClassUnderSpecification()
def coll = new Collaborator()
@Shared res = new VeryExpensiveResource()
static final PI = 3.141592654
9. 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
10. FEATURE METHODS
def "pushing an element on the stack"() {
// blocks go here
}
• Blocks
• Specification as Documentation
• Historias de usuario
12. HELPER METHODS
• Otros métodos
• Llamados desde tests
• Reutilizar código
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. LOGS
maximum of 7 and 0 is 7 FAILED
Math.max(a, b) == c
| | | | |
| 7 0 | 7
42 false
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. GEB
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" }
}