线程“main”中出现异常 java.lang.NoClassDefFoundError:使用 TestNG 时出现 org/slf4j/LoggerFactory 错误

问题描述 投票:0回答:2

我已经从市场安装了 testNG。我正在研究使用 Selenium 和 Java 进行软件测试。我希望用这个基本代码打印出来,但它显示错误。

package ui;

import org.testng.annotations.Test;

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

以下是错误。我没有在我的脚本或库中看到错误。我有什么遗漏的吗?

[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
selenium-webdriver testng testng-eclipse
2个回答
1
投票

我添加了以下依赖项,错误就消失了,

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

这就是输出。请注意下面前几行中的一些信息。虽然 testNG 仍然有效。

[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
===============================================


0
投票

这只是一个警告,我也有同样的情况,不影响测试执行。你可以直接忽略它

© www.soinside.com 2019 - 2024. All rights reserved.