Search code examples
springjunit4powermockito

all my jUnit tests in Jenkins return same error related to StackTraceCleanerProvider method isIn()


I inherited a Spring project that has about 160 failing JUnit Tests with Mockito classes

When I check in Jenkins, I see that every single test has the following Error details:

Receiver class org.powermock.api.mockito.internal.exceptions.StackTraceCleanerProvider$1 does not define or inherit an implementation of the resolved method 'abstract boolean isIn(java.lang.StackTraceElement)' of interface org.mockito.exceptions.stacktrace.StackTraceCleaner.

and the stacktrace is:

    at org.mockito.internal.exceptions.stacktrace.StackTraceFilter.filterFirst(StackTraceFilter.java:110)
    at org.mockito.internal.debugging.LocationImpl.computeStackTraceInformation(LocationImpl.java:50)
    at org.mockito.internal.debugging.LocationImpl.<init>(LocationImpl.java:35)
    at org.mockito.internal.debugging.LocationImpl.<init>(LocationImpl.java:26)
    at org.mockito.internal.debugging.LocationImpl.<init>(LocationImpl.java:22)
    at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:56)
    at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor$DispatcherDefaultingToRealMethod.interceptAbstract(MockMethodInterceptor.java:161)
    at org.mockito.codegen.ConfigurationService$MockitoMock$1748841625.getConfiguration(Unknown Source)
    at abcproductcomparisonaddon.compareviewproviders.impl.DefaultCompareViewAttributeDataProviderUnitTest.setUp(DefaultCompareViewAttributeDataProviderUnitTest.java:52)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at abc.ant.taskdefs.yunit.JUnitTestRunner.run(JUnitTestRunner.java:649)
    at abc.ant.taskdefs.yunit.JUnitTestRunner.launch(JUnitTestRunner.java:1374)
    at abc.ant.taskdefs.yunit.JUnitTestRunner.main(JUnitTestRunner.java:1164)```


I cannot find anything related to this error or exception.

I have no config access to the jenkins job, but I have the feeling that the used junit oder Mockito version in Jenkins is outdated.
When I run the tests locally per IntelliJ, i do not get the error.





Solution

  • The error message is saying that org.powermock.api.mockito.internal.exceptions.StackTraceCleanerProvider$1 does not provide an implementation for the isIn method, which is an abstract method in org.mockito.exceptions.stacktrace.StackTraceCleaner. This typically happens when the versions of PowerMock and Mockito being used are not compatible, and one of them (usually PowerMock) is relying on an outdated method signature.

    As a solution:

    1. Remove PowerMock if Possible: If you can, try using Mockito's built-in features to avoid PowerMock altogether. Mockito 3.x and above now support mocking static methods, constructors, and final classes, reducing the need for PowerMock.

    2. Downgrade Mockito Version: If updating PowerMock is not an option, you can try downgrading Mockito to a version that is compatible with the version of PowerMock you are using.