Spock: Support creation of mocks outside the Spock context and allow to associate such a mock with a specification

Created on 30 Aug 2015  路  12Comments  路  Source: spockframework/spock

Originally reported on Google Code with ID 305

Spock should offer an API that allows
* Creating a mock outside a Specification instance (for example a bean instance managed
by some container such as Spring, etc.)
* Associate such a mock with the current specification instance.


This would allow creating an integration test where complex interactions with external
resources such as 3rd-party services (web service) can be mocked. This is often requried
as these services are slow, accessible only with complex authentication, etc.

See also the forum discussion at https://groups.google.com/forum/?fromgroups=#!topic/spockframework/mKD4HD7tbEs

Reported by Martin.Ahrer on 2013-03-27 10:35:03

Module-Core Type-NewFeature

Most helpful comment

All 12 comments

When it comes to integration testing, an alternative (that I tend to prefer) is to hand-roll
a fake object. However, I understand that opinions on this matter differ, and it shouldn't
be too difficult to support this use case.

Reported by pniederw on 2013-03-27 11:12:27

I would be very interested in this feature and willing to help on the implementation.
It would be awesome if we could do something like Springokito's @ReplaceWithMock https://bitbucket.org/kubek2k/springockito/wiki/springockito-annotations

Reported by l.bruenings on 2013-07-10 17:56:55

Any news about this? I think the feature would still be useful.

See #17

Is there a 1.1 release (or even a beta release) coming anytime soon? We would like to use this feature in production.

We also need this feature.
I could not find any information about the planned 1.1 release. Is there a planned time or should we better use a snapshot build?

+1folks, this feature is much needed!

+1

Implemented in #546

Will be released in 1.1

@robfletcher could you share a quick example of how to do this?

@Blackbaud-JasonBodnar You can take a look into PRs diff. For example those tests.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrylis picture chrylis  路  9Comments

ShunmugamAiyappan picture ShunmugamAiyappan  路  5Comments

donbeave picture donbeave  路  5Comments

marceloverdijk picture marceloverdijk  路  7Comments

kriegaex picture kriegaex  路  5Comments