Reputation: 2535
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.
Upvotes: 205
Views: 217058
Reputation: 41
If you are using various libaries for testing
for example: JUnit and TestNG review your imports, you might have imported
@Test
from TestNG
instead of
@Test
from Junit
Human mistake was the reason the test was not being detected and excuted as expected
Upvotes: 0
Reputation: 21
I had the same issue. I used a character which was not an English one, renaming it solved my issue.
Ex. ı
-> i
.
Upvotes: 0
Reputation: 11
I had the same problem, finally, I found a duplicate test class in my project with the same package name and class name.
Upvotes: 0
Reputation: 252
I had the same issue, none of the solutions worked for me.
You can try the following steps:
.idea
folder in the file explorer and re-open the project.Upvotes: 0
Reputation: 1393
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
Upvotes: 0
Reputation: 21
follow the below steps in Intellij (with screenshots for better understanding):
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.
Upvotes: 1
Reputation: 230
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
Upvotes: 7
Reputation: 183
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
Upvotes: 3
Reputation: 91
Mark your package/directory as Test Sources in your IntelliJ IDEA.
Upvotes: 0
Reputation: 9263
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.
Upvotes: 16
Reputation: 2699
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
Upvotes: 0
Reputation: 396
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 :-)
Upvotes: 2
Reputation: 8641
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.
Upvotes: 1
Reputation: 430
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
Upvotes: 5
Reputation: 8979
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:
- Create new instrumented test class with different name.
- Copy all the code from your class.
- Run it.
- Delete the old class.
- Rename new class to desired name.
Upvotes: 5
Reputation: 4691
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
Upvotes: 6
Reputation: 1810
solved by manually run testClasses task before running unit test.
Upvotes: 0
Reputation: 1181
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.
Upvotes: 1
Reputation: 109
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
Upvotes: 1
Reputation: 520
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
Upvotes: 0
Reputation: 1308
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:
or:
or:
or:
Upvotes: 68
Reputation: 784
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
Upvotes: 7
Reputation: 12352
I went to
File -> Invalidate Caches/Restart...
and then it worked for me.
Upvotes: 75
Reputation: 3109
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
Upvotes: 3
Reputation: 7349
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'
}
Upvotes: 1
Reputation: 1585
For me the project was compiled outside the project. I just change the path. For changing the path (i'm using mac).
Upvotes: 1
Reputation: 1198
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.
Upvotes: 5
Reputation: 453
What worked for me was right click on the Project folder -> Maven -> Generate Sources and Update Folders
Upvotes: 0
Reputation: 5794
It's probably because the folder is not set as test source, which can be done via Module Settings > Modules.
Upvotes: 1