Failed to run JUnit test in IntelliJ

I wanted to start a project using TDD. Created a test directory and then changed it to a package integrated with src direcotry. In both cases, I get the same error:

Class not found: "tests.objectsTest"

I tried different methods of importing JUnit jar and none of the problems were solved. Also I tried to rename my test class, but it doesn't give any cuts.

It seems like IntelliJ or JUnit is changing the name of the test class. Shouldn't it be "objectsTest.tests"?

I am using JUnit version 4.12 and latest IntelliJ EAP.

EDIT This is my project structure:

Project:

-.idea
-src
  -logic
  -objects
-tests
  -test
   -test.java

      

src and tests are directories marked as Source and Test. Every package except the test is empty. On my other machine with IntelliJ Community Edition, everything works fine, but EAP has this error. Unfortunately I have to use EAP.

Test.java code:

package test;

import org.junit.Test;

public class test {

    @Test
    public void canCreateInhabitant(){

    }
}

      

+7


source to share


6 answers


Have you checked if the JUnit plugin is included? I (stupid, embarrassing!) Disabled it at some point and was unable to get IDEA to run my tests until I remembered how to enable the plugin back ...



+2


source


I made a simple test and put it on github .

This is the absolute simplest of the tests, but it works great, being inside the test class pressing shift+ ctrl+ twill run the test.



Go ahead and clone it and give it a try.

+1


source


Check the root directory of your classes. It must be marked as source (for Java classes) or test (for Java test classes).

It seems that your directory is not well marked in IntelliJ.

0


source


The easiest way:

  • Open the class in Intellij and press Ctrl + Shift + T
  • Select "Create New Test"
  • Now a new popup window will open where you can select Unit Test Library (for your case its Junit4)
  • Select the methods you want to include in the test
  • And there you go!
0


source


I sometimes find that this happens when I try to run "All Tests" from the project folder in the structure view. Running all tests by right clicking on the root test folder and selecting "all tests" seems to fix this problem.

0


source


It just happened to me. When I was building via Maven this was a problem. When I fixed the problem, it started the juntas again. Goofy.

0


source







All Articles