在 TestNg Runner 中我没有执行代码,但使用功能文件我得到结果
我需要使用 TestNg runner 执行。显示以下错误
[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
-generateResultsPerSuite
Should TestNG consider failures in Data Providers as test failures.
Default: false
-groups
Comma-separated list of group names to be run
-ignoreMissedTestNames
Ignore missed test names given by '-testnames' and continue to run
existing tests, if any.
Default: false
-includeAllDataDrivenTestsWhenSkipping
Should TestNG report all iterations of a data driven test as individual
skips, in-case of upstream failures.
Default: false
-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
-propagateDataProviderFailureAsTestFailure
Should TestNG consider failures in Data Providers as test failures.
Default: false
-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 运行 Cucumber 功能,请确保完成以下步骤:
包含 Cucumber-testNG 依赖项:https://mvnrepository.com/artifact/io.cucumber/cucumber-testng
Cucumber runner 类已创建,例如:
package testrunners;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(
features = "src/test/resources/features",
glue = {"stepdefinitions"},
plugin = {
"pretty",
"json:cucumber.json"
}
)
public class TestRunner extends AbstractTestNGCucumberTests {}
该类必须扩展 AbstractTestNGCucumberTests 类
src/test/resources/features 是包含 .feature 文件的文件夹的路径
stepdefinitions 是包的名称,其中包含已实现步骤的代码的类。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite" configfailurepolicy="continue" time-
out="60000">
<test name="Main tests">
<classes>
<class name="testrunners.TestRunner"/>
</classes>
</test>
</suite>
通过此设置,您应该能够运行 TestNG XML,它将执行位于指定文件夹中的所有 .feature 文件中的所有场景。