Вопрос

I have been seeing the use of "when" and "then" keyword in Groovy in several Groovy articles. One of them is here. I searched for the Groovy Doc's but I couldn't find it. So whats the actual purposes of these keyword's? Similar to if/then?

Это было полезно?

Решение

They aren't groovy keywords; they're actually constructs provided by some popular test frameworks. It looks like easyb and spock both use when and then.

In both cases, the test frameworks create a test specification DSL that looks human readable.

Другие советы

when and then, among others, seem to be documented here.

Technically the then, when and a few other constructs in Spock are good old labels (aka goto), which developers rarely use these days. Spock uses them to allow developers to logically and visually separate different aspects of their tests - assumptions, constraints, statements or data. The Spock compile-time AST transformations than use the labels to understand the structure of the test and do its magic.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top