question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"java.lang.NoSuchMethodError: org.mockito.Mockito.mockitoSession()" error in 'beforeEach' method inside MockitoExtension

See original GitHub issue

Dependecies:

junit-jupiter-api: 5.2.0 junit-jupiter-engine: 5.2.0 mockito-core: 2.18.3 mockito-junit-jupiter: 2.18.3

Test:

@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.WARN)
public class AccountTest
{
 @InjectMocks
  private Account account;
 @Mock
  private AccountConfiguration accountConfiguration;

 @Test
  public void shouldSetAccountInfoToRequest()
  {
     // test logic
  }
}

selection_267

Actual result:

java.lang.NoSuchMethodError: org.mockito.Mockito.mockitoSession()Lorg/mockito/session/MockitoSessionBuilder;
	at org.mockito.junit.jupiter.MockitoExtension.beforeEach(MockitoExtension.java:112)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachCallbacks$0(TestMethodTestDescriptor.java:129)
	at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:155)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

54reactions
kamilgregorczykcommented, Jan 5, 2019

I’m having the same issue

Ah, I removed:

<dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-all</artifactId>
      <version>1.10.19</version>
      <scope>test</scope>
    </dependency>

and it started working (I already had mockito-all)

5reactions
ChrisJBurnscommented, Jun 5, 2018

I also get this when doing something has basic as above. However, when I run the tests from the command line via Maven, there is no problem. It seems that I get this only when running the tests from within IntelliJ

Read more comments on GitHub >

github_iconTop Results From Across the Web

pom.xml - Stack Overflow
Can someone help me please what is my mistake? The error received: java.lang.NoSuchMethodError: org.mockito.Mockito.framework()Lorg/mockito/ ...
Read more >
NoSuchMethodError using 'when' on mockito 1.6
When running the test it fails on the 'when' method call with this error: java.lang.NoSuchMethodError: org.mockito.Mockito.when(Ljava/lang/
Read more >
Java.Lang.Nosuchmethoderror: Org.Mockito.Mockingdetails ...
java.lang.NoSuchMethodError: org.mockito.Mockito.mockitoSession error in 'beforeEach' method inside MockitoExtension #1394. java.lang.
Read more >
org.mockito.session.MockitoSessionBuilder.initMocks java ...
public void evaluate() throws Throwable { if (session == null) { session = Mockito.mockitoSession() .name(target.getClass().getSimpleName() + "." + method.
Read more >
java.lang.NoSuchMethodError: org.mockito.Mockito
This was giving me the following error when I ran the test case: java.lang.NoSuchMethodError: org.mockito.Mockito.when(Ljava/lang/Object ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found