Class not found: empty test suite in IntelliJ

I am just starting an informatics program at my college, and I have some problems with IntelliJ. When I try to run unit tests, I get a message

Process finished with exit code 1 Class not found: "edu.macalester.comp124.hw0.AreaTest"Empty test suite. 

I also see a message called "No Tests Found" on the left side of the 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 make my tests work? I am using the latest version of IntelliJ IDEA CE.

+168
java intellij-idea unit-testing junit
Sep 01 '16 at 23:29
source share
37 answers
  • one
  • 2

So my problem here was folder names. I named my Classes 2016/2017 code folder, which IntelliJ did not like. Just remove the slash (or other infringing character in the path), re-import the project, and you'll be fine!

+10
02 Sep '16 at 21:06
source share

Had the same message. I had to remove the Run / Debug configuration.

In my case, I used to run unit test as a local test. After that, I transferred my test to the androidTest package and tried to run it again. Android Studio remembered the last launch configuration, so it tried to run it again as a local unit test, which caused the same error.

After deleting the configuration and restarting the test, it generated a new configuration and worked.

enter image description here

+105
Dec 14 '16 at 12:29
source share

I went to

 File -> Invalidate Caches/Restart... 

and then it worked for me.

+49
Nov 02 '17 at 20:16
source share

I had the same problem. I rebuilt the project and it helped me.

Go to Build -> Rebuild Project

After that, if you use the Maven tool, I recommend using the Reimport All Maven Projects option


If this does not help, try other possible solutions:

  • Go to File -> Invalid Caches / Restart -> Invalid and restart

or:

  • In the structure of your Maven src / main / java project, right-click on the java directory and select the option Mark directory as → Sources Root

    Similarly, do the same with the test directory, like this: src / test / java, right-click on the java directory and select the option Mark directory as → Test sources Root

or:

  • Go to Run -> Edit Configurations and in the JUnit section delete the test configurations. Apply changes. After that, try running your tests. A new configuration should be created automatically.

or:

  • Go to File → Project Structure , select Modules , then select the desired module and go to the Paths tab.
    Check the parameters:
    The radio button Use compilation module output should be selected.

    The exit path should be inside your project. Also Test output path should be a directory inside your project. For example, it might look similar:
    Output path: C: \ path \ to \ your \ module \ yourModule \ target \ classes
    Test output path: C: \ path \ to \ your \ module \ yourModule \ target \ test-classes

    Exclude exit paths should deselect.
+41
Jan 23 '18 at 7:27
source share

This can also happen if your test folder was imported as a separate module (a small square is displayed on the folder icon in the project view).
Remove the module by selecting the test folder in the project view and press DEL .
Then run your test.
If an error message appears in a pop-up dialog box, then no module is selected, select the root module from the drop-down list.

+16
Nov 03 '16 at 11:16
source share

I had a similar problem after starting a new IntelliJ project. I found that the "module compilation path" for my module was not specified correctly. When I assigned the path in the "compile output path" module to the correct location, the problem was resolved. The output compilation path is assigned in the project settings. In the Modules section, select the appropriate module and go to the Paths tab ...

Paths tab in project settings | Module dialog

screenshot

... I sent the compiler output to a folder called "output", which is present in the Project parent folder.

+14
03 Feb '17 at 2:43 on
source share

In my case, everything else was 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 works as expected.

+14
Jul 10 '18 at 8:11
source share

In Android Studio 3.0+, sometimes UI tests are interpreted as unit tests in some way, and it doesn’t ask for a choice of target deployment. You can go to “Edit configuration” and mark it as an integration test, and it will start working

+7
Nov 30 '17 at 19:40
source share

I had the same question when I imported some jar from Maven and subsequently raised an empty-test-suite error.

In my case, it was because maven dropped the module files. Which I resolved by clearing my default configuration:

  • Open the project structure with shift - ctrl - alt - s shortcut

Screenshot of PModules Sources

  1. Look at Modules> Sources and fill out the Sources package or test package.
+5
Apr 30 '17 at 15:27
source share

I had the same problem and restoring / invalidating the cache, etc. It didn’t work. It seems like this is just a bug in Android Studio ...

The workaround is to simply run your unit tests from the command line with:

 ./gradlew test 

See: https://developer.android.com/studio/test/command-line.html

+5
Mar 05 '18 at 13:02
source share

Interestingly, I have come across this problem many times for various reasons. For example, Invalidating cache and restarting also helped.

The last thing I fixed by correcting the output path in File -> Project Structure -> Project -> Output of the project compiler to: absolute_path_of_package / out

e.g .: / users / random-guy / myWorkspace / src / DummyProject / out

+5
Mar 27 '18 at 0:31
source share

This will also happen if your module and / or jdk project are not configured correctly.

+4
Nov 07 '16 at 10:38
source share

Reimport project or module can solve the problem. I made this problem by renaming the package name during development. But the path of out and test output is the old way. Therefore intellij cannot find the class from the old path. Thus, the easiest way is to correct the exit path and the test exit path.

Configuring the Intellij module

+4
Aug 22 '17 at 7:53 on
source share

I had the same problem (Android Studio 3.2 Canary 4) and I tried most of the suggestions described in the other answers - but to no avail. Please note that this happened after I moved the file from test to the androidTest folder. It was still shown in the run configurations as a test, and not as an instrumental test.

I finally ended up creating a new file:

  1. Create a new instrumented test class with a different name.
  2. Copy all the code from your class.
  3. Run it.
  4. Delete the old class.
  5. Rename the new class to the desired name.
+4
Mar 07 '18 at 15:32
source share

If the project has a compilation problem, then the tests may not run. So, first build the project as Build -> Build Project. After successful compilation, repeat the test.

If all else fails, simply close the project window, delete the project, and re-import as the Gradle / Maven project, which will install everything for you, overriding existing files created by IntelliJ. This will delete the invalid created cache.

+3
Oct 17 '18 at 9:13
source share

Removing .idea and re-importing the SBT project solved this problem for me.

+2
May 08 '17 at 11:01
source share

In my case, IntelliJ did not compile test sources for some strange reason. I just changed the build configuration and added the maven clean test-compile target in the Before launch section

+2
Oct 15 '17 at 0:35
source share

I had the same problem. In my case, I had some test classes in a folder / folder outside the main folder. But when I checked the Startup configuration, he always tried to look for classes inside the main folder (and not my packages outside the main folder). Therefore, if this is the case, you need to either move your packages to the locations indicated by the startup setting. Or modify the run configuration to point to your packages.

+1
Dec 21 '16 at 21:56
source share

Does your test require an Android device (emulator or hardware)?
If so, it is called a "tool test" and is located in "module-name / src / androidTest / java /".
If not, it is called "local unit test" and is located in "module-name / src / test / java"

https://developer.android.com/training/testing/start/index.html

I have the same error because I wrote a local unit test, but it was placed in the folder for instrumental tests. Moving the local unit test to the "src / test / java" folder has been fixed for me.

+1
Apr 02 '17 at 4:02 on
source share

The same error turned out. My device was not connected to Android studio. When I connected to the studio. It is working. This solves my problem.

+1
Apr 2 '17 at 17:20
source share

Probably because the folder is not set as the source of the test, which can be done through "Module Settings"> "Modules".

+1
May 15, '17 at 15:22
source share

In my case, the problem was fixed by going to my build.gradle and changing

 dependencies { testImplementation 'junit:junit:4.12' } 

to

 dependencies { testCompile 'junit:junit:4.12' } 
+1
Sep 29 '17 at 9:48 on
source share

I tried all the solutions, but none of them helped. In the end, I run the test in debug mode and .... it started working. Maybe some maven cache has been cleared. It is hard to say. It is working. Try mvn test -X

+1
Feb 09 '18 at 8:51
source share

Just right-click on the file in the project windows and select

"Run YourTest ."

Now everything starts fine, possibly because the incorrect launch configuration is rebuilt again.

+1
Feb 22 '18 at 14:50
source share

This can happen (at least once for me;) after installing a new version of IntelliJ, and IntelliJ plugins are not yet updated.

You may need to manually Check for updates… from the IntelliJ help menu.

+1
Apr 7 '18 at 4:55
source share

In the structure of your Maven src / main / java project, right-click on the java directory and select the option Mark directory as → Sources Root

Similarly, do the same with the test directory, like this: src / test / java, right-click on the java directory and select the option Mark directory as → Test sources Root

Worked for me :-)

+1
Jul 10 '18 at 13:01
source share

In my case, there was a problem with the name of the test :).

If the name was: dummyNameTest , then do not get the tests where they were found, but in the case of testDummyName everything was fine

+1
Apr 01 '19 at 12:12
source share

IDEA 15.0.6 is used in the same release, and nothing helped except when I renamed the package in which the test class was located. After that, I renamed it back to the original name and still worked, so the rename action could clear some cache.

0
Dec 06 '16 at 23:44
source share

For me, this was because my project was cataloged outside the project. The paths of the output path were \ production \ project_name and \ test \ project_name, which put them in C: \ production \ project_name. Changing them to the full path of the project allowed my tests to access class files.

0
Mar 06 '17 at 16:44
source share

I had the same problem in my environment (macOS). I used IntelliJ 2016. I had a Java library project (gradle).

What I did was

  • An open / exported project from an older version of IntelliJ (e.g. IntelliJ14). This happened successfully, and I tested it by running a project and running a test case.
  • Then I imported this project again through IntelliJ 2016. After that, it worked fine (construction and test scenario).
0
Apr 18 '17 at 9:08 on
source share
  • one
  • 2



All Articles