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.
I had the same question when I import some
jar
from Maven, and subsequently, cause theempty-test-suite
error.In my case, it was because the maven resetting the module files. Which I resolved by clearing my default configuration:
In my case there was a problem with test name :).
If name was:
dummyNameTest
then get no tests where found, but in casetestDummyName
everything was okIt's probably because the folder is not set as test source, which can be done via Module Settings > Modules.
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.
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.
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