Behavior Driven Development for java – what framework to use? [closed]

Behavior Driven Development is just a technique that can be used without any tools. You can just write tests in BDD style – e.g. start test methods with should and introduce some separate feature with this method. When and then sections can be replaced with just comments, e.g. @Test public void should_do_something() { // given … Read more

Running spock unit tests with Maven

This answer is purely supplemental to @PeterNiederwieser’s answer. In it he mentions that you can configure the name pattern used by Surefire. Here is an example of what worked for me: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18</version> <configuration> <includes> <!– By default only files ending in ‘Test’ will be included, so also include support for Spock style … Read more

what does >> and 1* means in this groovy statement?

This is not groovy per se, but the testing framework called Spock (which is very popular among Groovy developers, for good reasons 🙂 – http://spockframework.github.io/spock/docs/1.0/index.html This expression in particular is a way to instruct Spock that it should expect exactly one call to the method prova in myService, and that this call should be mocked … Read more

How to start Spring Boot app in Spock Integration Test

The problem is that Spock Spring is looking for Spring’s @ContextConfiguration annotation and doesn’t manage to find it. Strictly speaking MyTestSpec is annotated with @ContextConfiguration as it’s a meta-annotation on @SpringApplicationConfiguration but Spock Spring doesn’t consider meta-annotations as part of its search. There’s an issue to address this limitation. In the meantime you can work … Read more

Spock: can an interaction defined in setup() be replaced in a test case?

That’s a tricky one. As stated in the docs, interactions declared in a then-block have precedence over interactions declared earlier. However, interactions declared in a then-block are scoped to the previous when-block. (This allows to have multiple when-then pairs.) Hence your last try doesn’t work, but the following will: def setup() { bar.message >> “hello” … Read more