Groovy Spock "old" method
A good unit test is simple and have just a few lines. Spock has an awesome feature called "old" method that help us to keep our groovy tests even more clean and readable, take a look:
def "A test using the 'old' method from Spock"(){
    when: "I increment a number"
        number++
    then: "It must me greater than it was before"
        assert number > old(number)
    where: "we might have any kind of number"
        number << [497, 76.5, 0.01, -1]
}The method gives us the value of a certain variable as it was at the beginning of the test.
Pretty cool, huh? :D
Written by Mário Melo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Groovy 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
 
 
