Expand my Community achievements bar.

SOLVED

Error while running a Junit5 test case in IntelliJ

Avatar

Level 5

I am writing a JUnit5 test case for a servlet that is creating a JsonObject object. While running the test case in my IDE (IntelliJ), I'm getting the below error - 

goyalkritika_0-1682404551035.png

But, on the other hand, my core package build is successful. How to get this error resolved in my IDE as I can see that the dependency jar is getting downloaded while maven build.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @goyalkritika  - 

 

Couple of things, did you validated the following : 

  • Are your test cases running successfully? Hope you are not accidentally skipping the test cases while running the test cases on your local machine.
  • Also, the gson dependency should be also available in test scope as well : 

    <dependency> 

    <groupId>com.google.code.gson<groupId>

    <artifactId>gson</artifactId>

    <version>2.8.0</version>

    <scope>test</scope>

    </dependency>

View solution in original post

4 Replies

Avatar

Employee Advisor

Hi @goyalkritika ,

 

Looks like IDE specific error. you could try the following.

 

  • Try to reload the dependencies in IntelliJ,
  • Reload/Restart with cache invalidation.
  • Check the module setting for the project in the IDE, if you are able to find the dependencies.
  • Check the scope of dependency, (Is it set to test), and also check if it's included in parent/core POM.

 

Also check this thread on the stack, https://stackoverflow.com/questions/51489823/noclassdeffounderror-when-trying-to-execute-junit-4-tes... 

 

Hope this helps!

 

Regards,

Nitesh

 

Avatar

Community Advisor

Hi @goyalkritika ,

This could happen due to a missing JAR file or JAR was not added into classpath or sometimes jar's name has been changed.
What you would need to do is that delete your existing m2 repo and try to build the code again, and see if you still getting this error.


Avatar

Correct answer by
Community Advisor

Hello @goyalkritika  - 

 

Couple of things, did you validated the following : 

  • Are your test cases running successfully? Hope you are not accidentally skipping the test cases while running the test cases on your local machine.
  • Also, the gson dependency should be also available in test scope as well : 

    <dependency> 

    <groupId>com.google.code.gson<groupId>

    <artifactId>gson</artifactId>

    <version>2.8.0</version>

    <scope>test</scope>

    </dependency>