AssertJ/Mockito "NoSuchMethodError" from a version conflict - Fix in CI
Your tests compiled against one version of AssertJ or Mockito but a different (older) version is on the runtime test classpath. A method that exists at compile time is absent at run time, so the JVM throws NoSuchMethodError.
What this error means
A test errors with java.lang.NoSuchMethodError: org.assertj.core.api.AbstractAssert.as(...) or a Mockito/ByteBuddy method, even though it compiles. The conflict comes from a transitive pin (often a Spring Boot BOM or another testing library).
java.lang.NoSuchMethodError: 'org.mockito.MockedStatic
org.mockito.Mockito.mockStatic(java.lang.Class)'
at com.example.ServiceTest.setUp(ServiceTest.java:22)
at java.base/jdk.internal.reflect...Common causes
Transitive dependency pins an older version
A managed BOM or another library forces an older AssertJ/Mockito than the API you wrote against.
Mockito and ByteBuddy out of sync
Mockito needs a compatible ByteBuddy; an old ByteBuddy on the classpath breaks newer Mockito APIs like mockStatic.
Two test libraries bundle different versions
Mixing test starters can introduce duplicate, mismatched AssertJ/Mockito jars.
How to fix it
Inspect and align the versions
Find which version actually resolves, then pin the one your tests need.
./gradlew dependencyInsight --configuration testRuntimeClasspath \
--dependency org.mockito:mockito-coreForce a consistent version
Pin Mockito/AssertJ (and ByteBuddy) so one version wins.
dependencies {
testImplementation 'org.mockito:mockito-core:5.12.0'
testImplementation 'org.assertj:assertj-core:3.26.0'
constraints { testImplementation 'net.bytebuddy:byte-buddy:1.14.18' }
}Override the BOM-managed version (Maven)
Declare the test library version explicitly to override a BOM pin.
<properties>
<mockito.version>5.12.0</mockito.version>
</properties>How to prevent it
- Let one BOM manage test-library versions and do not mix conflicting starters.
- Keep Mockito and ByteBuddy on compatible versions.
- Run
dependencyInsight/dependency:treewhen a NoSuchMethodError appears.