Skip to main content
removed salutation
Source Link
GhostCat
  • 140.7k
  • 28
  • 190
  • 262

I updated my project with the latest revision of Spring (2.0.0.RELEASE) and while my tests worked in 2.0.0.RC1, now it doesn't work and it keeps giving me this error :

org.mockito.exceptions.base.MockitoException: Cannot instantiate @InjectMocks field named 'service'! Cause: the type 'PersonService' is an interface. You haven't provided the instance at field declaration so I tried to construct the instance. Examples of correct usage of @InjectMocks: @InjectMocks Service service = new Service(); @InjectMocks Service service; //and... don't forget about some @Mocks for injection :) 

Here I made a minimal project where you can change the version in the pom file to see it succeed on 2.0.0.RC1 and fail in 2.0.0.RELEASE.

For the a full minimal test - please turn to Minimal Test Reproduction on Githubgituhub

Thanks in advance :).

I updated my project with the latest revision of Spring (2.0.0.RELEASE) and while my tests worked in 2.0.0.RC1, now it doesn't work and it keeps giving me this error :

org.mockito.exceptions.base.MockitoException: Cannot instantiate @InjectMocks field named 'service'! Cause: the type 'PersonService' is an interface. You haven't provided the instance at field declaration so I tried to construct the instance. Examples of correct usage of @InjectMocks: @InjectMocks Service service = new Service(); @InjectMocks Service service; //and... don't forget about some @Mocks for injection :) 

Here I made a minimal project where you can change the version in the pom file to see it succeed on 2.0.0.RC1 and fail in 2.0.0.RELEASE.

Minimal Test Reproduction on Github

Thanks in advance :)

I updated my project with the latest revision of Spring (2.0.0.RELEASE) and while my tests worked in 2.0.0.RC1, now it doesn't work and it keeps giving me this error :

org.mockito.exceptions.base.MockitoException: Cannot instantiate @InjectMocks field named 'service'! Cause: the type 'PersonService' is an interface. You haven't provided the instance at field declaration so I tried to construct the instance. Examples of correct usage of @InjectMocks: @InjectMocks Service service = new Service(); @InjectMocks Service service; //and... don't forget about some @Mocks for injection :) 

Here I made a minimal project where you can change the version in the pom file to see it succeed on 2.0.0.RC1 and fail in 2.0.0.RELEASE.

For the a full minimal test - please turn to gituhub.

Source Link
uknys
  • 59
  • 6

Mockito Bug in Spring 2.0.0.RELEASE

I updated my project with the latest revision of Spring (2.0.0.RELEASE) and while my tests worked in 2.0.0.RC1, now it doesn't work and it keeps giving me this error :

org.mockito.exceptions.base.MockitoException: Cannot instantiate @InjectMocks field named 'service'! Cause: the type 'PersonService' is an interface. You haven't provided the instance at field declaration so I tried to construct the instance. Examples of correct usage of @InjectMocks: @InjectMocks Service service = new Service(); @InjectMocks Service service; //and... don't forget about some @Mocks for injection :) 

Here I made a minimal project where you can change the version in the pom file to see it succeed on 2.0.0.RC1 and fail in 2.0.0.RELEASE.

Minimal Test Reproduction on Github

Thanks in advance :)