Git Product home page Git Product logo

Comments (3)

pchudzik avatar pchudzik commented on July 28, 2024

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.

M21B8 avatar M21B8 commented on July 28, 2024

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.

pchudzik avatar pchudzik commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.