Linked Questions
40 questions linked to/from Injecting Mockito mocks into a Spring bean
43
votes
2
answers
103k
views
How to inject a Mock in a Spring Context [duplicate]
I have a test that is using some Spring contexts. In these contexts, a number of beans are declared.
I want the test to use the actual implementation of the beans of the contexts, EXCEPT for one of ...
1
vote
1
answer
2k
views
Injecting mocks into Spring test Mockito + Spring + TestNG [duplicate]
I want to write a test for a printing service. I am using Spring with TestNG and Mockito.
So far I've created a test configuration class for my spring context and the needed test class.
The ...
0
votes
1
answer
726
views
Mockito mocks and ensuring method level spring security is tested [duplicate]
I'm trying to test some controller with method-level spring security and I want to mock out the repository dependencies in the controller. Basically I want to test that (a) the methods are enforcing ...
79
votes
7
answers
121k
views
Mockito, JUnit and Spring
I started to learn about Mockito only today. I wrote some simple test (with JUnit, see below), but I can't figure out how can I use mock object inside Spring's managed beans. What is best practices ...
27
votes
5
answers
23k
views
Using @MockBean in tests forces reloading of Application Context
I have several integration tests running on Spring Framework that extend the base class called BaseITCase.
Like this:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {...
22
votes
4
answers
55k
views
How does Mockito @InjectMocks work?
Here's my question:
I have several web services classes to test that all inherit their methods from a generic service. Rather than write a unit test for each, I figure I can break the test suite down ...
33
votes
3
answers
33k
views
How to tell spring to only load the needed beans for the JUnit test?
A simple question that might have an advanced answer.
The Question:
My question is, is there a way to instantiate only the classes, in your application context, needed for that specific JUnit test ?
...
13
votes
5
answers
12k
views
Transactional annotation avoids services being mocked
I have a drools rule file which uses service classes in the rules. So one rule does something like this:
eval(countryService.getCountryById(1) != null)
In a validationservice that is annotated with @...
8
votes
6
answers
12k
views
Using Mockito annotations with spring
I am using spring in my application and I want to write unit tests for all my classes. I call few external webservices from my application and i want to mock them using Mockito since I just want to ...
9
votes
5
answers
8k
views
Make a fake javax.sql.DataSource?
I have to write tests with String Test framework where many DB connections was used.
In test I don't need all data sources but Spring want them all to inject.
Are there any standard or well known ...
3
votes
3
answers
24k
views
Mockito Injecting Null values into a Spring bean when using @Mock?
As I am new to Spring Test MVC I don't understand this problem. I took the code below from http://markchensblog.blogspot.in/search/label/Spring
Variable mockproductService is not injected from ...
6
votes
5
answers
11k
views
Spring + Mockito test injection
My question is very similar to the issue raised in Injecting Mockito mocks into a Spring bean. In fact, I believe the accepted answer there might actually work for me. However, I've got one issue ...
8
votes
1
answer
4k
views
Creating unitary tests in Spring 3
I'm starting on testing applications in general and I want to create several tests to learn Mockito in Spring. I've been reading several information but I have some general doubts I'd like to ask.
I ...
4
votes
3
answers
8k
views
Mocking Spring beans
I'd like to continue this question.
These answers foo and bar are exactly what I would need.
But for the bar example spring doesn't infer the type of bean that is returned from generic mock() method....
2
votes
2
answers
10k
views
How can I mock a field in a Spring controller test using mockito?
I'm trying to autowire a mocked DAO object for my Spring (v. 3.1.0.RELEASE) test and using Mockito 1.9.0. The controller class with the field I want to mock is
@Controller
@RequestMapping("/...