I've got JUnit tests that run just fine. Added Mockito to my build and I try to put a breakpoint in my JUnit test that uses Mockito to mock out some of the public methods. When I try to run the debugger on the class, I get the error "unable to install breakpoint in XXX due to missing line number attributes. Modify compiler options to generate line number attributes." I checked my compiler and I generate line numbers is selected.
To debug a JUnit test via Eclipse, simply place your breakpoints as expected, and then right click the test method and choose “Debug As” -> “JUnit Test”. The test will start and will pause when the breakpoint is hit.
JUnit and Mockito can be primarily classified as "Testing Frameworks" tools. JUnit and Mockito are both open source tools. It seems that Mockito with 9.02K GitHub stars and 1.62K forks on GitHub has more adoption than JUnit with 7.53K GitHub stars and 2.8K GitHub forks.
Mockito can also be used with other testing frameworks like JUnit and TestNG. JUnit framework is a Java framework that is also used for testing. Now, JUnit is used as a standard when there is a need to perform testing in Java.
With the test class open in the Eclipse editor, simply right click in the editor view and select Debug As > TestNG Test. Eclipse will stop at any breakpoints you set just like it would with any other local debug process.
The exception you're seeing is caused by attempting to debug dynamically generated empty mock methods created by the mock() function. From your question, it looks like you actually want to be using partial mocks instead of full mocks, where only some methods are mocked and the remaining calls are delegated to the real implementation.
To create partial mocks, you should be using the spy() method instead of the mock() method. So, use
MyClass myMock = spy(new MyClass());
instead of
MyClass myMock = mock(MyClass.class);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With