[SOLVED] JUnit tests fail with "Emtpy test suite" and exception from LoggerFactory IntelliJ 2017.2.5

Answered

Hi,

having tried a lot of suggestions from other posts here and around the web but ran out of ideas.

I upgraded to IntelliJ 2017.2.5 and the JUnit tests won't start since this upgrade. I think that it has something to do with JUnit5. I added the following Maven dependency:

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M4</version>
<scope>test</scope>
</dependency>

The error log is:

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/commons/logging/LoggerFactory
    at org.junit.platform.launcher.core.DefaultLauncher.<clinit>(DefaultLauncher.java:44)
    at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:59)
    at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:45)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.logging.LoggerFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

I don't see anything special in my test classes either (a little bit stripped down to the basics)

package worker.specialclasses;

import basicvalues.Constants;
import jdk.nashorn.internal.ir.annotations.Ignore;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import worker.MyClass;

import java.io.IOException;
import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.*;


class MySpecialClassTest {
    private static MySpecialClass mMySpecialClassInstance;

    @BeforeAll
    static void setUp() throws Exception {
        mMySpecialClassInstance = MySpecialClass.getInstance();
    }

    @AfterEach
    @Ignore
    void tearDown() {
    }

    @Test
    void getInstance() throws Exception {
        assertNotNull(mMySpecialClassInstance);
    }

    @Test
    void getSpecialClass() {
        assertNotNull(mMySpecialClassInstance.getSpecialClass());
    }

    @Test
    void getApiUsername() {
        assertEquals(Constants.USERNAME, mMySpecialClassInstance.getApiUsername());
    }


}

If you have any ideas, I'd greatly appreciate!

Thank you in advance and kind regards

0
7 comments

Please check http://junit.org/junit5/docs/current/user-guide/#running-tests-ide-intellij-idea .

If the issue persists, try https://www.jetbrains.com/idea/nextversion/ .

In case it also doesn't help, please file a bug at https://youtrack.jetbrains.com/issues/IDEA with the sample project to reproduce attached.

0
Avatar
Permanently deleted user

Hi Serge and thank you for your response!

First, just to get it right: following the JUnit documentation there is no need to add a dependency in my pom.xml unless I want to use a newer or the legacy ("vintage") version of JUnit, rather then the build-in version of IntelliJ? This did not work for me and I had to add the junit-jupiter-api 5.0.0-M4 in my pom.xml to resolve all dependency problems.

However, using the "newversion" release did the trick. Before I upgraded I created a very simple project with a very simple JUnit test class and ran into the same problem with the latest community release. Switching to the "newversion" release resolved the problem (in my main project, too).

I'm still wondering what could be so "special" about my project (even the simple one), because it seems to me that nobody had experienced the same problem yet (I suppose that it would have been reported earlier otherwise). If I can help in finding the cause of my reported problem, please let me know. For now, my issue is solved. Thank you for your help, Serge!

0

2017.2.5 bundles junit 5.0.0 thus you need additional dependencies when you try to run with older M4 (as stated in the junit 5 user guide, the problem is that until released they were not backward/forward compatible). 2017.3 EAP downloads all required dependnecies automatically based on version of jupiter.api specified in user's project, thus you don't need to change anything.

Hope this helps,

Anna

0
Avatar
Permanently deleted user

@stilltldr did you find any way out ? I'm facing the same problem. 

Here is my pom.xml

https://pastebin.com/Z5KKsVaY 

This is my stacktrace

https://pastebin.com/pczjkErP 

This is the java file for test

https://pastebin.com/3ydfCdZV 

 
0
Avatar
Permanently deleted user

Hi,

no, not yet unfortunatly. I'm also running into problems regarding updated maven dependencies: when i change the version of my used dependencies in the pom.xml to a higher number, the old jars are still used even though they are already in my .m2 folder.

KR

0
Avatar
Permanently deleted user

Hm, interesting: when I executed

mvn dependency:resolve

at least the new dependecies are downloaded.

0
Avatar
Permanently deleted user

I finally fixed it!

1) executed with my terminal:

mvn dependency:resolve

This downloaded all dependencies (I would have expected this that IntelliJ did this?)

2) I deleted the content from the local "lib" folder

Now the correct dependencies are being used, BOTH for my auxiliary library AND JUnit!

Could you reproduce this for your issue? @Muztaba Hasanat 

0

Please sign in to leave a comment.