#Junit not recongnized

39 messages · Page 1 of 1 (latest)

rich dove
#

how do I fix this:

Exception in thread "main" java.lang.IllegalAccessError: class org.junit.platform.engine.UniqueId (in unnamed module @0x73c6c3b2) cannot access class org.junit.platform.commons.util.Preconditions (in module org.junit.platform.commons) because module org.junit.platform.commons does not export org.junit.platform.commons.util to unnamed module @0x73c6c3b2
    at org.junit.platform.engine.UniqueId.forEngine(UniqueId.java:69)
    at com.intellij.junit5.JUnit5IdeaTestRunner.<clinit>(JUnit5IdeaTestRunner.java:72)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:375)
    at com.intellij.rt.junit.JUnitStarter.getAgentClass(JUnitStarter.java:241)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:222)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)```
rocky narwhalBOT
#

This post has been reserved for your question.

Hey @rich dove! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

cedar nymph
#

Can you show your pom.xml/build.gradle?

#

specifically I'm interested in your JUnit dependencies including their versions

#

though this seems like it could be an IntelliJ issue - can you try running these tests from the command-line?

rich dove
cedar nymph
rich dove
cedar nymph
rich dove
#

i am unsure, i think intellij auto installed because i highlighted over the error and pressed install junit and then the errors went away

rich dove
cedar nymph
#

In the imports of your test classes, do you have org.junit.Test or org.junit.jupiter.api.Test?

cedar nymph
#

I think if your press ctrl in IntelliJ twice, it should show a box with Run anything

cedar nymph
cedar nymph
rich dove
#
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< com.example:Proj3 >--------------------------
[INFO] Building Proj3 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- resources:3.3.0:resources (default-resources) @ Proj3 ---
[INFO] Copying 0 resource
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ Proj3 ---
[INFO] Changes detected - recompiling the module! :source
[INFO] Compiling 6 source files with javac [debug target 17 module-path] to target\classes
[WARNING] /C:/Users/ethan/IdeaProjects/Proj3/src/main/java/module-info.java:[1,19] module name component proj3 should avoid terminal digits
[INFO] 
[INFO] --- resources:3.3.0:testResources (default-testResources) @ Proj3 ---
[INFO] skip non existing resourceDirectory C:\Users\ethan\IdeaProjects\Proj3\src\test\resources
[INFO] 
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ Proj3 ---
[INFO] No sources to compile
[INFO] 
[INFO] --- surefire:3.0.0:test (default-test) @ Proj3 ---
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.340 s
[INFO] Finished at: 2023-10-07T17:04:19-04:00
[INFO] ------------------------------------------------------------------------
[WARNING] 
[WARNING] Plugin validation issues were detected in 1 plugin(s)
[WARNING] 
[WARNING]  * org.apache.maven.plugins:maven-resources-plugin:3.3.0
[WARNING] 
[WARNING] For more or less details, use 'maven.plugin.validation' property with one of the values (case insensitive): [BRIEF, DEFAULT, VERBOSE]
[WARNING] 

Process finished with exit code 0```
rich dove
#
package com.example.proj3;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;```
cedar nymph
#

ok so you are mixing JUnit 4 and JUnit 5 in your test

#

which one do you want to use?

#

You need to decide for one

rich dove
#

well i did not write this JUnit file, it was given as code to use to test my project

#

i guess 4, since it's more stable

#

if i wanted to keep 4, what would I do?

cedar nymph
#

then you need to remove all the org.junit.jupiter stuff

rich dove
cedar nymph
#

both from the test and the pom.xml

cedar nymph
rich dove
cedar nymph
rich dove
#

thank you!

rocky narwhalBOT
# rich dove thank you!

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.