“Spock” Talk at ExpoQA 2019, Madrid

Gil Zilberfeld describes his upcoming talk "Spock" on the unit testing framework that allows clean code and readable tests.
Standard

“Why do we need another testing framework”?

Next week, I’m giving a brand new talk at the expoQA conference in Madrid. It’s on Spock – the unit testing framework, not the Starfleet commander. The first question I need to answer is – isn’t JUnit enough?

Sure, there’s TestNG, but other than that – why do we need another unit test framework in the Java world?

The simple answer is – you probably don’t. Spock doesn’t do much beyond JUnit. Actually behind the facade, it does everything that JUnit + Mockito do.

But if we take a step back, we can ask – why do we need other languages on the JVM on top of Java?

When you take a look at Groovy (or Kotlin), you start seeing a difference between how code is written and can be read. You write less code for your program to work, and the language makes the code more readable, and therefore easier to understand and maintain. It’s clean code 101, but it starts even before you write a single line.

Let’s take it back to JUnit and Spock. Can we write readable JUnit tests? Sure, but it requires some extra boiler plate code we need to hide, and a a whole lot of discipline. Spock tests, written in Groovy, are already lighter in code, but also have the label keywords (given, when, then, expect) to make the tests more readable.

Yes, we still need to invest in good names and abstractions. This doesn’t go away. But the experience is more fluid.

Here’s an example of the Spock tests I’m going to show at expoQA.

See, Avengers (and starfleet) make everything cooler.

See you in Madrid!

Leave a Reply

Your email address will not be published. Required fields are marked *