All Projects → snekse → spring-spock-integration-testing

snekse / spring-spock-integration-testing

Licence: other
How to inject Spock mocks into Spring integration tests

Programming Languages

groovy
2714 projects

Projects that are alternatives of or similar to spring-spock-integration-testing

spock-mockable
Mock the un-mockable
Stars: ✭ 22 (+29.41%)
Mutual labels:  spock-framework
spock
Automatically perform git commits, pushes, and other cli actions when Statamic content changes
Stars: ✭ 96 (+464.71%)
Mutual labels:  spock
springmock
alternative spring mocking infrastructure
Stars: ✭ 22 (+29.41%)
Mutual labels:  spock
spring-boot-web-application-sample
Real World Spring Boot Web Application Example with tons of ready to use features
Stars: ✭ 143 (+741.18%)
Mutual labels:  spock
junit2spock
JUnit test to Spock test converter
Stars: ✭ 15 (-11.76%)
Mutual labels:  spock
gathering
A self hosted website for announcing group events
Stars: ✭ 39 (+129.41%)
Mutual labels:  spock
funblog
A simple blog software written in Haskell
Stars: ✭ 84 (+394.12%)
Mutual labels:  spock
geb-mobile
A geb navigator factory for mobile support for Appium, Selendroid and IosDriver
Stars: ✭ 18 (+5.88%)
Mutual labels:  spock
onboarding-service
Backend Onboarding Service for Tuleva
Stars: ✭ 21 (+23.53%)
Mutual labels:  spock
job-dsl-sample
Jenkins Job DSL Sample Project
Stars: ✭ 32 (+88.24%)
Mutual labels:  spock
Spock
The Enterprise-ready testing and specification framework.
Stars: ✭ 3,056 (+17876.47%)
Mutual labels:  spock-framework

How to inject Spock mocks into Spring integration tests

This project is intended to be used as en example guide to illustrate how you can use Spock with Spring (and Spring Boot) with a mix of Spring configuration and Spock mocks.

Sometimes you want to do fuller integration tests with your entire Spring context in place. This usually leads to those handful of problem spots that you'd rather just mock.

In Spring Boot 1.4, they introduced a lot of cool testing toys, including @MockBean. Sadly that's only supported when testing with JUnit.

Thankfully Spock 1.1 introduced the DetachedMockFactory. This, combined with the new Spring Boot @TestConfiguration means you can achieve a level up in your testing happiness factor.

The heart of this example lives in our PersonControllerIntTest. The PersonControllerIntTest spins up a Spring context so we can make a MockMvc call to a REST endpoint which pulls data from an h2 database via a Spring Data repo, but the "Rank" data we would normally get from an external service has been mocked.

Testing provided by Travis CI Build Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].