Coder Social home page Coder Social logo

therore-spring-mockito's People

Contributors

alfredodiaz avatar knes1 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

therore-spring-mockito's Issues

@MockedBean fields are processed for all classes containing them

Hi Alfredo

I have come across your repo and the solution in this repo https://github.com/hobo05/mockitobeans in my attempt to achieve some easy mocking in my Spring integration tests.
All though yours is a bit different from the MockitoBeans, I still wanted to post my question to you here.

Using the MockitoBeans approach I have two integration test classes associated with a Spring Boot application.
Each of the test classes have the @MockedBeans but each with different mocked classes.
For instance TestClassA has a BeanA which it wants mocked and TestClassB has a BeanB which it wants mocked.
However, when I run either test, both @MockedBeans occurrences are picked up by the registrator and thus both mocks are created and the actual beans are not available in either test.

I would like to be able to scope the effect of the @MockedBean so that it only registers what is on the test class being executed.

Would that be possible with your solution?

If not, I would very much appreciate any advice you might have as to how it might be possible inside the Bean registrator class to get information about the current JUnit test being executed.
My idea is that if JUnit can provide the name of the test about to be run, then it would be easy to simply just register mocks for that given class and ignore the rest of the mock enabled test classes.
My assumption here is that when a full mvn test run is executed, the mocks are loaded for each test so that this strategy would also work when running all tests and not just a single one.

@hobo05 had an idea about filtering away other test classes which have the @MockedBean in the ComponentScan. That approach might work, but I would prefer a solution which is least intrusive to the test code - meaning that fewer lines of code are to prefer.

Again, thank you for your time.

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.