2.2. Groovy Power assert as a replacement for JUnit asserts

With the def mystery solved, the second striking feature of Spock tests is the lack of assert statements for evaluating results. All JUnit tests end with one or more assert statements[6] that define the expected result of the computation. If the expected result doesn’t match the actual one, the test will fail. JUnit comes with an extensive API for assert statements, and it’s considered a good practice to create your own extensions, dealing with the business domain of your application.

6

Not having an assert (or verify) statement is a huge antipattern, because the test never fails.

I mentioned in the previous chapter that unlike JUnit, Spock doesn’t have assert methods. In this section, ...

Get Java Testing with Spock now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.