Linkage Error Loader Constraint Violation - JUnit test case development issue

July 22, 2017

Its good to write unit tests cases, and this part is mostly forgotten by developers. It can ease various issues that can come up while integrations.

I’m listing down various issues or problems that we faced while writing JUnit test cases:

LinkageError: Loader constraint violation

Stacktrace:

Solution

This is the issue you face when somewhere in your dependency you are using a component whose mock is not supported by mock libraries. Or, mock libraries can not mock a class.

In this case, the solution is to tell PowerMock that please ignore particular package to mock. We are asking mock loader not to load particular package/classes.

And, you can do this by putting an annotation on top of class like below:

@PowerMockIgnore("javax.management.*")

And, next time you run, the issue is gone. Enjoy


Similar Posts

Latest Posts