New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@InjectMocks seems doesn't work since 5.2.0 in some cases #3221
Comments
@alexey-komarov I could see you are using ExtendWith(MockitoExtension.class) and again MockitoAnnotations.openMocks(this). When you are using ExtendWith, no need to use openMocks again as MockitoExtension automatically manages opening and closing mocks in the test class. You can try removing BeforeEach method and try once. Also, using Autowired is also unnecessary in this scenario it seems for me |
@Saik2930 Also, I found it doesn't work even with 5.1.1 when I'm running with Spring Boot (in the attached example there is only Spring without Spring Boot for the simplicity). I think the issue is that I'm trying to mock generic object in my base class:
because once I replaced it with
and added the required getter to the child TestTaskHandler class like this:
I was able to mock QueueService with
and everything started to work correctly. |
I think I also experience this problem. I am seeing NullPointerExceptions on tests that inject a generic mock into an abstract class. In my case Mockito 5.1.0 works fine. The problem occurs in 5.2.0 onwards. I suspect #3019 might be also be related to this. |
+1 |
Hey,
I'm working on migrating an old project from Java 8 to OpenJDK 21 plus upgrading all dependencies.
I have migrated some unit tests from Junit 4/Mockito 4 to latest junit-jupiter 5/Mockito 5.8 and some tests don't work as expected. I have tried to downgrade Mockito to check if there is a regression and surprisingly found it works with Mockito 5.1.1 as expected. I didn't dig into it further, but I was able to create a very simple isolated reproducible case, please see attached testmock.tar.gz (I use gradle 8.5 to build and run tests).
testmock.tar.gz
The text was updated successfully, but these errors were encountered: