ssacher-tgm / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Clover Coverage for Setters using InjectMocks and Mock annotations. #210

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. A Class under test containing setters for dependencies.
2. The Unit Test class creating an Object of the Class under test using 
InjectMocks annotation.
3. Run the Test class using Clover 2 for test coverage showing 0% coverage for 
the setters.
4. Create another test class without InjectMocks for the Class under test. Use 
the setter methods to inject dependencies, in the init method of the test class.
5. Run the Test class using Clover 2 for test coverage, showing 100% coverage 
for the setters.

What is the expected output?
Expected output should be 100% coverage for the setter methods, while using 
@InjectMocks annotation.

What do you see instead?
I see 0% coverage for the setter methods, which using @InjectMocks.

What version of the product are you using?
Using version 1.8.3

On what operating system?
Windows XP.

Please provide any additional information below.
The code build is being run using TeamCity and Code coverage is being 
calculated using Sonar and Clover version 2. If needed, I can provide you the 
minor version of TeamCity, Sonar and Clover.

Original issue reported on code.google.com by arpit...@gmail.com on 10 Aug 2010 at 3:29

GoogleCodeExporter commented 8 years ago
Hello, the @InjectMocks javadoc is actually wrong, the injection code, is field 
based.
So it's quite expected to see a 0% coverage regarding the setters.

It allows dependency injection without breaking your tested object API with 
setters.

I you want to change the default configuration of mockito, declaring a new 
org.mockito.configuration.MockitoConfiguration extending 
DefaultMockitoConfiguration or implementing IMockitoConfiguration.
Or you might want to provide a path allow both field and setter injection you 
might want to provide a patch. 

Original comment by brice.du...@gmail.com on 10 Aug 2010 at 6:02

GoogleCodeExporter commented 8 years ago
>Hello, the @InjectMocks javadoc is actually wrong

I know :) We have that fixed in trunk.

>you might want to provide a patch.

That would be good. I intend to change mockito to use setters if they are 
available. 

Cheers,
szczepan

Original comment by szcze...@gmail.com on 11 Aug 2010 at 9:31

GoogleCodeExporter commented 8 years ago
High szczepan

> That would be good. I intend to change mockito to use setters if they are 
available. 

When coding for the i209 enhancement, I saw you would like to refactor the 
engine in a CoR pattern; I like that. If you are busy, I can work on it in the 
next weeks.

btw when say this:
>you might want to provide a patch.
I was talking to Arpit :)

Original comment by brice.du...@gmail.com on 12 Aug 2010 at 9:16

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 13 Aug 2010 at 6:54

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 3 Sep 2012 at 10:00