Class Not Found: Empty Test Suite in IntelliJ
JavaUnit TestingIntellij IdeaJunitJava Problem Overview
I'm just starting the computer science program at my college, and I'm having some issues with IntelliJ. When I try to run unit tests, I get the message
Process finished with exit code 1
Class not found: "edu.macalester.comp124.hw0.AreaTest"Empty test suite.
I also see a message entitled "No tests were found" on the left side of my screen. My test code is here:
package edu.macalester.comp124.hw0;
import org.junit.Test;
import static org.junit.Assert.*;
public class AreaTest {
@Test
public void testSquare() {
assertEquals(Area.getSquareArea(3.0), 9.0, 0.001);
}
@Test
public void testCircle() {
assertEquals(Area.getCircleArea(3.0), 28.2743, 0.001);
}
}
And my project code is here:
package edu.macalester.comp124.hw0;
import java.lang.Math;
public class Area {
/**
* Calculates the area of a square.
* @param sideLength The length of the side of a square
* @return The area
*/
public static double getSquareArea(double sideLength) {
// Has been replaced by correct formula
return sideLength * sideLength;
}
/**
* Calculates the area of a circle.
* @param radius The radius of the circle
* @return The area
*/
public static double getCircleArea(double radius) {
// Replaced by correct value
return radius * 2 * Math.PI;
}
}
How can I get my tests to work? I'm using the most recent version of IntelliJ IDEA CE.
Java Solutions
Solution 1 - Java
Had the same message. I had to remove the Run/Debug configuration.
In my case, I ran the unit test as a local test before. After that I moved my test to the androidTest package and tried to run it again. Android Studio remembered the last run configuration so it tried to run it again as a local unit test which produced the same error.
After removing the config and running the test again it generated a new configuration and worked.
Solution 2 - Java
I went to
File -> Invalidate Caches/Restart...
and then it worked for me.
Solution 3 - Java
I had the same issue. I rebuilded project, and it helped me.
Go to Build --> Rebuild Project
After then, if you are using Maven tool, I recommend use option Reimport All Maven Projects
If it not help, try another possible solutions:
- Go to File-->Invalidate Caches/Restart--> Invalidate and Restart
or:
- In your Maven project structure src/main/java right click on java directory and select option Mark directory as --> Sources Root
Similarly do the same with test directory so: src/test/java right click on java directory and select option Mark directory as --> Test Sources Root
or:
- Go to Run --> Edit Configurations and in section JUnit remove test configurations. Apply changes. After then try to run your tests. New configuration should be created automatically.
or:
-
Go to File --> Project Structure, select Modules, then select your proper module and go to the Paths tab.
Check options:
Radio button Use module compile output path should be selected.
Output path should be inside your project. Also Test output path should be directory inside your project. For example it can look similarly:
Output path: C:\path\to\your\module\yourModule \target\classes
Test Output path: C:\path\to\your\module\yourModule \target\test-classes
Exclude output paths should be deselected.
Solution 4 - Java
This might also happen, if your test folder has been imported as a separate module (a small square is shown on the folder icon in the project view).
Remove the module by selecting the test folder in the project view and press DEL.
Then start your test.
If a popup dialog appears with an error message, that no module is selected, specify your root module from the dropdown.
Solution 5 - Java
In my case, I had everything else in the right place, but I was working on a java library with kotlin. I just forgot to apply the plugin:
apply plugin: 'kotlin-android'
And now it's working as expected now.
Solution 6 - Java
I had a similar problem after starting a new IntelliJ project. I found that the "module compile output path" for my module was not properly specified. When I assigned the path in the module's "compile output path" to the proper location, the problem was solved. The compile output path is assigned in the Project settings. Under Modules, select the module involved and select the Paths tab...
Paths tab in the Project Settings | Modules dialog
...I sent the compiler output to a folder named "output" that is present in the parent Project folder.
Solution 7 - Java
So, my issue here was with folder names. I had called my code folder Classes 2016/2017, which IntelliJ didn't like. Simply remove the slash (or other offending character in path), re-import the project, and you'll be good to go!
Solution 8 - Java
In Android Studio 3.0 +, sometimes UI tests are somehow interpreted as unit tests and it doesn't ask for target deployment selection. You can go to Edit Configuration and mark it as an Integration test and it would start working
Solution 9 - Java
If the project has compilation issue then tests might not run. So firstly build project as Build -> Build Project. After successful compilation re-run the test.
If nothing works out then just close the project window and delete project and re-import as Gradle/Maven project which will set everything for you by overriding the existing IntelliJ created files.This will remove invalid cache created.
You can also just invalidate the cache.
File -> Invalidate Caches/Restart
Solution 10 - Java
I had the same problem and rebuilding/invalidating cache etc. didn't work. Seems like that's just a bug in Android Studio...
A temporary solution is just to run your unit tests from the command line with:
./gradlew test
See: https://developer.android.com/studio/test/command-line.html
Solution 11 - Java
I had the same question when I import some jar
from Maven, and subsequently, cause the empty-test-suite
error.
In my case, it was because the maven resetting the module files. Which I resolved by clearing my default configuration:
- Open Project structure with shift-ctrl-alt-s shortcut
- Look at the Modules > Sources and fill the Sources package or test Package.
Solution 12 - Java
Deleting .idea
and re-importing the SBT project solved this issue for me.
Solution 13 - Java
Reimport project or module can solve the issue. I made this issue by renaming package name when developing. But the out path and test output path is the old path. So intellij can't find the class from the old path. So the easiest way is correcting the out path and test output path.
Solution 14 - Java
I had the same issue (Android Studio 3.2 Canary 4) and I tried most of suggestions described in other answers - without any success. Note this happened after I moved the file from test
to androidTest
folder. It was still shown in run configurations as test instead of instrumented test.
I finally end up with creating a new file:
> 1. Create new instrumented test class with different name. > 2. Copy all the code from your class. > 3. Run it. > 4. Delete the old class. > 5. Rename new class to desired name.
Solution 15 - Java
Interestingly, I've faced this issue many times due to different reasons. For e.g. Invalidating cache and restarting has helped as well.
Last I fixed it by correcting my output path in File -> Project Structure -> Project -> Project Compiler Output to : absolute_path_of_package/out
for e.g. : /Users/random-guy/myWorkspace/src/DummyProject/out
Solution 16 - Java
This will also happen when your module- and/or project-jdk aren't properly configured.
Solution 17 - Java
In my case, IntelliJ didn't compile the test sources for a strange reason. I simply modified the build configuration and added the maven goal clean test-compile
in the Before launch
section
Solution 18 - Java
In my case there was a problem with test name :).
If name was:
dummyNameTest
then get no tests where found, but in case
testDummyName
everything was ok
Solution 19 - Java
In your Maven project structure src/main/java right click on java directory and select option Mark directory as --> Sources Root
Similarly do the same with test directory so: src/test/java right click on java directory and select option Mark directory as --> Test Sources Root
Worked for me :-)
Solution 20 - Java
I had the same issue. In my case i had some test classes in a package/folder outside of the main folder. But when i checked the Run configuration, it was always trying to look for classes inside the main folder (and not my packages outside of main) . So if that is the case , you either have to move your packages to where the Run configuration is pointing to. Or change the run configuration to point to your packages.
Solution 21 - Java
Does your test require an Android device (emulator or hardware)?
If so, it's called an "instrumented test" and resides in "module-name/src/androidTest/java/".
If not, it's called a "local unit test" and resides in "module-name/src/test/java"
https://developer.android.com/training/testing/start/index.html
I got the same error because I had written a local unit test, but it was placed in the folder for instrumented tests. Moving the local unit test to the "src/test/java" folder fixed it for me.
Solution 22 - Java
Was getting same error. My device was not connected to android studio. When I connected to studio. It works. This solves my problem.
Solution 23 - Java
It's probably because the
Solution 24 - Java
For me the project was compiled outside the project. I just change the path. For changing the path (i'm using mac).
- Go to File --> Project Structure
- Go to Module on left side.
- Select Paths, select radio button(use module compile output path)
- Provide output path and Test output path which is inside your project
- Deselect Exclude output paths.
- Go to File --> Click on Invalidate Cache and restart
Solution 25 - Java
In my case, the problem was fixed by going into my build.gradle
and changing
dependencies {
testImplementation 'junit:junit:4.12'
}
to
dependencies {
testCompile 'junit:junit:4.12'
}
Solution 26 - Java
I tried all solutions but none of them helped. At the end i run test in debug mode and.... it started to work. Maybe some maven's cache was cleared up. It is difficult to say. It works. Try mvn test -X
Solution 27 - Java
Just click your mouse right button on the file in Projects windows and select
"Run YourTest".
Everything just starts OK now, probably because faulty run configuration is being rebuild anew.
Solution 28 - Java
This can happen (at least once for me ;) after installing the new version of IntelliJ and the IntelliJ plugins have not yet updated.
You may have to manually do the Check for updates…
from IntelliJ Help menu.
Solution 29 - Java
follow the below steps in Intellij (with screenshots for better understanding):
- go to Files --> Project structure
-
navigate to modules and now select the module, in which your Junit test file present and select "Use module compile output path" radio button.
-
Mention the respective classes folder path, similar to the screenshot attached.
- Do apply and Okay. This worked for me!
Solution 30 - Java
Same issue here using IDEA 15.0.6, and nothing helped except when I renamed the package the test class was in. Afterwards I renamed it back to its original name and it still worked, so the rename action might have cleared some cache.
Solution 31 - Java
For me it was because my project was being compiled into a directory outside of the project. In paths the output paths were \production\project_name and \test\project_name which was putting them in C:\production\project_name. Changing them to the full path of the project allowed my tests to access the class files.
Solution 32 - Java
I had the same issue in my environment also (MacOS). I was using IntelliJ 2016. I had a Java library project (gradle).
What I did was
- Opened/exported project from a IntelliJ older version (like IntelliJ14). This happened successfully and I verified it with by making the project and by running a test case.
- Then I imported that project again via IntelliJ 2016. After that it worked fine(building and test case running).
Solution 33 - Java
What worked for me was right click on the Project folder -> Maven -> Generate Sources and Update Folders
Solution 34 - Java
solved by manually run testClasses task before running unit test.
Solution 35 - Java
My fix for this issue was with folder names and paths.
My test were missing /java/ folder for some reason and IntelliJ didn't like that.
so from ../test/com/.. to ../test/java/com/..
and it is ok
Solution 36 - Java
First thing, we need to understand why this is happening and the error message is clear:
> Process finished with exit code 1 > Class not found: "edu.macalester.comp124.hw0.AreaTest"Empty test suite.
So this mainly occurs when after the unit test class was created we run the methods (tests) individually before running them from the class level. That is all
Solution 37 - Java
Mark your package/directory as Test Sources in your IntelliJ IDEA.
Solution 38 - Java
Removing and recreating of run congiguration also helps.
Solution 39 - Java
I didn't compile the code.
To Fix the issue, I did the following.
Go to Maven -> Click on Execuate Maven Goal
Run the command
mvn test-compile
and choose the project from the drop down.
Now go and run your test, It will work
Solution 40 - Java
I had the same issue, none of the solutions worked for me.
You can try the following steps:
- Close the project in Intellij IDEA.
- Remove the
.idea
folder in the file explorer and re-open the project. - Run the tests again.