JUnit 5 cannot resolve symbol Assertion. Test class not in TEST scope.
I created a JUnit5 test by clicking on "create Test" from the intention menu (light-bulb). A dialog said something like "create test on source root". I said OK (it was the only option). I also clicked on "Fix" to import JUnit5 library, and I chose "use JUnit5 of IntelliJ" (the other option was to copy JUnit to lib/).
Now, the test .java file cannot compile: "Error:(3, 36) java: package org.junit.jupiter.api does not exist".
If I do "Project structure -> Modules -> Dependencies tab", and change the JUnit5 scope from "TEST" to "Compile" it works. So I presume it is a problem with the layout of my project. I tried creating src/test/ and putting the .java file there, but it doesn't work. My project layout is as follow:
./iri.iml
./src
./src/com
./src/com/company
./src/com/company/myproj
./src/com/company/myproj/subpackage
./src/com/company/myproj/subpackage/Config.java
./src/com/company/myproj/subpackage/Log.java
./src/com/company/myproj/subpackage/Main.java
./src/com/company/myproj/subpackage/MyClass.java
./src/com/company/myproj/subpackage/MyClassTest.java
./.idea
./.idea/vcs.xml
./.idea/modules.xml
./.idea/workspace.xml
./.idea/kotlinc.xml
./.idea/misc.xml
./.idea/inspectionProfiles
./.idea/inspectionProfiles/Project_Default.xml
What should I do?
Thanks.
Please sign in to leave a comment.
Test scope of the libraries works for the files that are in the Test Sources roots, how is your source root configured? See https://www.jetbrains.com/help/idea/configuring-content-roots.html.
Wonderful. I did: "Project structure -> Modules -> Sources tab", then I created a new directory and marked it as Test. Then I recreated the test. It has been placed in the right folder and it compiles.
Thanks!