Class Not Found: Empty Test Suite in IntelliJ

2020-01-27 09:56发布

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.

30条回答
Ridiculous、
2楼-- · 2020-01-27 10:20

This will also happen when your module- and/or project-jdk aren't properly configured.

查看更多
在下西门庆
3楼-- · 2020-01-27 10:20

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.

查看更多
Melony?
4楼-- · 2020-01-27 10:20

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'
}
查看更多
手持菜刀,她持情操
5楼-- · 2020-01-27 10:22

Deleting .idea and re-importing the SBT project solved this issue for me.

查看更多
祖国的老花朵
6楼-- · 2020-01-27 10:23

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

查看更多
beautiful°
7楼-- · 2020-01-27 10:24

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.

enter image description here

查看更多
登录 后发表回答