For this reason, we have to mock the void method to simulate the various … Mockito Tutorial The solution gives you JUnit itself. Mockito test a void method throws an exception - Stack OverflowthrownMocking Static Methods With Mockito Void method throws an exception Question: Write a java program that uses Mockito on a method that returns a void and throws an exception. DEVTIP :: Mockito test a void method throws an exception Mockito provides full support for mocking void methods, which we will see with examples in this article. For Mockito, there is no direct support to mock private and static methods. In order to test private methods, you will need to refactor the code to change the access to protected (or package) and you will have to avoid static/final methods. Credits. Java answers related to “mockito void method throw exception”. However, there are very rare situations when the doNothing () method comes handy. Void method throws an exception | Java code