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 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:
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:
or:
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.
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!
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
For me the project was compiled outside the project. I just change the path. For changing the path (i'm using mac).
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
I went to
and then it worked for me.