Comments (3)
You can check if latest snapshot version will work for you (it probably will not, it might fix the error but you'll probably hit more complicated issues later).
I've refactored the check that was raising the exception. It doesn't make any sense and I didn't considered that someone might use spock and junit at the same time, although I did it myself :)
The problem might a bit more complicated that it looks. Right now mockito and spock infrastructure are completely different and separated things. Each one setups some stuff, and as a results one will overwrite beans registered by another. For example double factory might get overwritten and as a result you can end up with spock mocks in junit test case.
if that's the case then you'll need to do some coding to get this running
Annotate your test class with @BootstrapWith and provide TestContextBootstraper which will call org.springframework.test.context.support.AbstractTestContextBootstrapper#getContextCustomizerFactories and then remove all springmock customizers and then add one customizer for each testing framework. Something like this:
class JunitSpringMockContextCustomizer extends DefaultTestContextBootstrapper {
@Override
protected List<ContextCustomizerFactory> getContextCustomizerFactories() {
return Stream.concat(
super.getContextCustomizerFactories().stream().filter(this::isNotSpringMockCustomizer),
Stream.of(new com.pchudzik.springmock.mockito.spring.MockitoContextCustomizerFactory())
).collect(toList());
}
}
and very similar one for spock but use com.pchudzik.springmock.spock.spring.SpockContextCustomizerFactory instead of MockitoContextCustomizerFactory. You can try and figure out the single class which will do it more dynamically but I'm sure you get the idea.
Now about long term solution. How should it look? I see few options here but I'm not sure which one will the best.
- leave it as is if it is be working. I don't expect it to work...
- allow to manually select mocking library and disable/enable it for single test classes (sounds like a lot of effort for the user to select runner for each test class individually...) Something like the workaround I've proposed above, maybe looking a bit better on the outside but still pretty ugly...
- automagically detect what is being executed and (spock specification/junit test case) and register infrastructure appropriately - might be tricky to maintain in longer perspective. Something like the workaround above but bundled in the library.
- something else?
from springmock.
The 1.1.0-SNAPSHOT actually works for us, all our tests pass once I use that version :) Any chance of it becoming a release version?
Thanks
from springmock.
I've just released version 1.1.0 to maven central.
testCompile('com.pchudzik.springmock:springmock-mockito:1.1.0')
Since it's working for you then I'm closing this one. In case of any further issues do not hesitate to reopen.
from springmock.
Related Issues (17)
- Figure out unified testing infrastructure/interfaces to ensure that mocking library works HOT 1
- Determine beanName just like what `@MockBean` do HOT 4
- mockito spies are not resetted HOT 1
- Check if it's working with spring5 HOT 1
- check if it works with spring data repositories HOT 1
- Null Pointer exception when names don't match up HOT 2
- Allow to leave spring proxy as it is when creating spies HOT 2
- Support new default value of spring boot 2.1 of spring.main.allow-bean-definition-overriding HOT 16
- Add support for different groovy versions when using spock HOT 1
- allow to create mocks without injecting them into specification HOT 2
- add support for additional configuration HOT 1
- support for java7 HOT 1
- configure automated deployment HOT 1
- Question about WebMvcTest support HOT 7
- spy should be distinguished from mock if they are both of the same class HOT 3
- inject mocks by name HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from springmock.