@TestNg [TestNG] 未找到测试。没有运行任何内容 用法:<main class> [选项] 要运行的 XML 套件文件

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

当我使用“@Test”注释运行测试 ng 方法时,我们遇到异常并且测试未运行。

TestNG 类

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 String 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"));
        return "URL is found";
     }
}

当我将此测试作为 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-combined-3.141.59-sources.jar”作为我的项目中的引用库。作为测试结果,我可以看到以下内容

此控制台错误消息


[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 
    -parallel
      Parallel mode (methods, tests or classes)
      Possible Values: [tests, methods, classes, instances, none, true, false]
    -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

我想运行使用 testNg 的测试,上面的代码没有任何错误或异常。

selenium-chromedriver spring-data testng testng-eclipse
1个回答
0
投票

我们有办法解决上述bug。

  1. 如果你的测试ng方法有一个非void返回类型[Not void]。
© www.soinside.com 2019 - 2024. All rights reserved.