Ad-Hockery

ad-hockery: /ad·hok'@r·ee/, n.
Gratuitous assumptions... which lead to the appearance of semi-intelligent behavior but are in fact entirely arbitrary. Jargon File

Articles tagged ‘testing’

Jerry: a jQuery like API for DOM parsing

When unit testing things that produce HTML output (such as some Grails taglibs) there are some common pitfalls. Comparing large chunks of markup with an expected string is very brittle; whitespace and attribute ordering becomes significant. Often people end up using regular expressions or assertions like assert output.contains('<div id="foo">'). Whilst it may be a bit more maintainable this doesn’t really test correct DOM structure which is often important and again, attribute order can be a problem.

Read more…

Testing Angular forms with Casper

When testing an Angular application using Casper I found that the binding between inputs and model didn’t seem to be happening when I filled in form fields. I used Casper’s fill method but found that the Angular form validation was rejecting any required fields as though they were still blank. With some debugging I was able to see that the $scope variables indeed weren’t getting updated.

Read more…

Derived values in Spock where tables

When using where blocks in Spock there are two forms; assigning iterable values to a variable, e.g. crew << ['Mal', 'Kaylee', 'Jayne'] or using a datatable. In the first form I always knew you could use assigned values, for example:

where:
crew << ['Mal', 'Kaylee', 'Jayne']
nameLength = crew.length()

Note the assignment operator used rather than the left shift on the second line there.

Read more…


Testing callbacks with Spock mocks

I’ve been doing some work with vert.x over the last few days and trying to develop components that are test-driven. Like any asynchronous framework rather than having methods that return a value you pass a callback Closure that gets invoked at some point in the future with the result. This makes it tricky to write unit tests that mock out collaborators as you might in a traditional app.

Read more…

Spock Killer Features: The “old” method

I use Spock almost exclusively to test Groovy or Java code these days. It’s got some fantastic features that other test frameworks don’t have. Some of them aren’t that well known or documented, though.

The old method is possibly my favourite Spock feature. It’s a simple thing but really enhances test legibility. It’s also great for wowing developers new to Spock because it looks like black magic at first glance.

Read more…

Wiring taglib dependencies in Grails 2 unit tests

Grails 2 has made a lot of improvements in unit testing support. One of the things I always used to find particularly painful was unit testing taglibs. Now when your test class is annotated with @TestFor(MyTagLib) you can use the applyTemplate method like this:

expect:
applyTemplate('<my:tag/>') == 'the expected output'

However, one thing I found is that it’s quite tricky to wire a dependency in to the taglib instance that’s used by the applyTemplate method.

Read more…


Fear & loathing in functional testing land

As projects grow the two things I’ve repeatedly found to be particularly painful have been functional testing and data fixtures. I might write up some thoughts on data fixtures another time but what follows is a brain-dump of my troubled relationship with functional testing.

Disclaimers: I have more questions than answers and I’m completely open to the idea that I’m doing it all wrong. I’m not trying to diss any tool or technique here. I have spent a lot of time over the last few years writing functional test coverage so I think I at least have some perspective on the issues if no clue how to solve them.

Read more…

Running Geb tests from your IDE

A frequent complaint about functional testing in Grails is that the start up / shut down cycle time of the app makes prototyping a functional test prohibitive. There has been some recent progress in this are with Luke Daley’s Functional test development plugin but it would be really nice to be able to just run functional tests from inside your IDE in the same way as a similar unit test.

Read more…

Web Statistics