如何解决'[TestNG] No tests found. Nothing was run'



我正在尝试使用Eclipse IDE通过TestNG运行selenium。下面给出了我的代码。

package testNGtest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class loginlogout {
public WebDriver driver;
String driverPath = "D:\chromedriver.exe";
public String BaseURL = "https://xxxx.com/login";
@Test
public void loginPage() {               

System.out.println(BaseURL);
System.setProperty("webdriver.chrome.driver", driverPath);
driver= new ChromeDriver();     
driver.get(BaseURL);
String currentUrl=driver.getCurrentUrl();
Assert.assertTrue(currentUrl.contains("/login"));
}
}

当我将这个测试作为testNG测试运行时,它显示[testNG]未找到任何测试。没有运行任何内容。但当我只使用运行时

System.out.println(BaseURL);

它显示BaseURL,但在添加其余代码时,显示未找到任何测试。我使用的是chrome浏览器版本91.0.4472.124和chrome驱动程序版本,我从https://chromedriver.storage.googleapis.com/index.html?path=91.0.4472.101/并将其保存到我的D驱动器中。在我的项目中,我添加了两个jar文件"client-combined-3.141.59.jar和client-combinerd-3.141.59-sources.jar"作为引用库。作为测试结果,我可以看到以下

[RemoteTestNG] detected TestNG version 7.4.0
===============================================
Default test
Tests run: 0, Failures: 0, Skips: 0
===============================================

===============================================
Default suite
Total tests run: 0, Passes: 0, Failures: 0, Skips: 0
===============================================
[TestNG] No tests found. Nothing was run
Usage: <main class> [options] The XML suite files to run
Options:
-alwaysrunlisteners
Should MethodInvocation Listeners be run even for skipped methods
Default: true
-configfailurepolicy
Configuration failure policy (skip or continue)
-d
Output directory
-dataproviderthreadcount
Number of threads to use when running data providers
-dependencyinjectorfactory
The dependency injector factory implementation that TestNG should use.
-excludegroups
Comma-separated list of group names to  exclude
-failwheneverythingskipped
Should TestNG fail execution if all tests were skipped and nothing was 
run. 
Default: false
-groups
Comma-separated list of group names to be run
-junit
JUnit mode
Default: false
-listener
List of .class files or list of class names implementing ITestListener 
or ISuiteListener
-methods
Comma separated of test methods
Default: []
-methodselectors
List of .class files or list of class names implementing IMethodSelector
-mixed
Mixed mode - autodetect the type of current test and run it with 
appropriate runner
Default: false
-objectfactory
List of .class files or list of class names implementing 
ITestRunnerFactory 
-overrideincludedmethods
Comma separated fully qualified class names of listeners that should be 
skipped from being wired in via Service Loaders.
Default: false
-parallel
Parallel mode (methods, tests or classes)
Possible Values: [tests, methods, classes, instances, none]
-port
The port
-reporter
Extended configuration for custom report listener
-spilistenerstoskip
Comma separated fully qualified class names of listeners that should be 
skipped from being wired in via Service Loaders.
Default: <empty string>
-suitename
Default name of test suite, if not specified in suite definition file or 
source code
-suitethreadpoolsize
Size of the thread pool to use to run suites
Default: 1
-testclass
The list of test classes
-testjar
A jar file containing the tests
-testname
Default name of test, if not specified in suitedefinition file or source 
code 
-testnames
The list of test names to run
-testrunfactory, -testRunFactory
The factory used to create tests
-threadcount
Number of threads to use when running tests in parallel
-threadpoolfactoryclass
The threadpool executor factory implementation that TestNG should use.
-usedefaultlisteners
Whether to use the default listeners
Default: true
-log, -verbose
Level of verbosity
-xmlpathinjar
The full path to the xml file inside the jar file (only valid if 
-testjar was specified)
Default: testng.xml

我不明白这里出了什么问题。有人能帮我吗?

当我在创建Java项目时将JRE部分中的JavaSE-16更改为JavaSE-1.8时,它成功运行,没有修改代码中的任何内容。

在子类中调用启动浏览器的父类方法。

我今天在项目中遇到了类似的问题。测试类本身看起来不错,但没有找到任何测试。

因此,我们在testng测试执行中进行了调试,发现NoClassDefFoundError异常在";isTestNGClass";方法,当通过ClassHelper类中的getAvailableMethods方法。

当抛出异常时;isTestNGClass";方法返回false,导致类不是testng类,以便找不到测试。

引发异常的原因是基类的基类移动到另一个包并且该包不包括在pom的依赖项中。

因此,找不到这一类,因此NoClassDefFoundError,因此该类不是testng导致0个测试要处理的类。

相关内容

  • 没有找到相关文章

最新更新