Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to run JUnit test in IntelliJ

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

Class not found: "tests.objectsTest"

I tried different techniques of importing JUnit jar and none solved problem. Also I tried to rename my test class but it gives no solutons whatsoever.

It seems that IntelliJ or JUnit changes name of the test class. Shouldn't it be objectsTest.tests?

I am using JUnit version 4.12 and latest IntelliJ EAP.

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 test is empty. On my other PC with IntelliJ Community Edition everything works fine but on EAP there is this bug. Unfortunatelly I have to use EAP.

test.java code:

package test;

import org.junit.Test;

public class test {

    @Test
    public void canCreateInhabitant(){

    }
}
like image 863
wizzle Avatar asked Jul 08 '15 13:07

wizzle


2 Answers

Have you checked if you have the JUnit plugin enabled? I (foolishly, shame!) disabled it at some point and was unable to get IDEA to run my tests until I remembered to turn the plugin back on...

like image 152
RDM Avatar answered Sep 30 '22 18:09

RDM


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.

like image 41
Davide Lorenzo MARINO Avatar answered Sep 30 '22 18:09

Davide Lorenzo MARINO