Enable Mockito Tests: An Interface for Context
See original GitHub issueIf Context
would be an interface instead of a class, it could easily be mocked in unit tests.
My router delegates certain paths to controllers that have methods which only take a Context
object. If this would be an interface, I could mock it and only unit test my controller in isolation.
All the test examples I have found in this repository use full integration test that I would like to avoid (at least for my controller unit tests).
Issue Analytics
- State:
- Created 5 years ago
- Comments:46 (22 by maintainers)
Top Results From Across the Web
Enable Mockito Tests: An Interface for Context #335 - GitHub
So I'm stuck with various solutions: Add PowerMock to lightweight Mockito2 library in tests (somewhat unsatisfying since we'd only need that for ...
Read more >unit test a interface implementation with mock in Spring Boot
You are running your tests with SpringRunner but for mocks you don't really need spring context. Try following code // Using mockito runner ......
Read more >Unit tests with Mockito - Tutorial - Vogella.com
This tutorial introduces the usage of Mockito for JUnit tests. ... A mock object is a dummy implementation for an interface or a...
Read more >Clean Unit Tests with Mockito - Reflectoring
Mockito allows us to create a suitable test double for the CityRepository interface and lets us define the behavior we expect from it....
Read more >Injecting Mockito Mocks into Spring Beans - Baeldung
We use the @ActiveProfiles annotation to enable the “test” profile and activate the mock configuration we wrote earlier. As a result, Spring ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For people arriving here wondering how to do mocking with Mockito
HttpServletRequest
andHttpServletResponse
, then pass them toContextUtil.init()
. The init function is overloaded to take all the dependencies ofContext
:Yep, thanks for your work @tipsy!