taerese
taerese

Reputation: 67

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory error using TestNG

I have installed my testNG from the marketplace. I am studying software testing using Selenium with Java. I expect a print out with this basic code, instead, it displays an error.

package ui;

import org.testng.annotations.Test;

public class LoginTest {
    
    @Test
    public void loginTest()
    {
        System.out.println("hi hello");
    }
}

Following is the error. I did not see error in my script or the library. Is there anything I am missing?

[RemoteTestNG] detected TestNG version 7.8.0
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.testng.log4testng.Logger.lambda$getLogger$0(Logger.java:30)
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
    at org.testng.log4testng.Logger.getLogger(Logger.java:30)
    at org.testng.TestNG.<clinit>(TestNG.java:113)
    at org.testng.remote.support.RemoteTestNGFactory7_8.createRemoteTestNG(RemoteTestNGFactory7_8.java:16)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:67)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 6 more

Upvotes: 1

Views: 4061

Answers (3)

wizcoderx
wizcoderx

Reputation: 11

(IF YOUR NOT USING MAVEN) Well in this scenario you will need to download the JAR files in zip, extract it and later add the External JAR files in the 'build-path' under the 'Classpath' section. Download the slf4j-api JAR and slf4j-simple JAR from the given website, yeah its not secure but its safe I have used it to download these JAR files when I run into the same problem, http://www.java2s.com/

enter image description here

Upvotes: 0

Ivan Patiuk
Ivan Patiuk

Reputation: 1

It is just a warning, I have the same, and it does not affect the test execution. You can simply ignore that

Upvotes: 0

taerese
taerese

Reputation: 67

I added the following dependencies are the error was gone,

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>2.0.7</version>
</dependency>

This was the output. Notice some information in first few lines below. Although the testNG still works.

[RemoteTestNG] detected TestNG version 7.8.0
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
hi hello
PASSED: ui.LoginTest.loginTest

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================

Upvotes: 2

Related Questions