Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在套件中从testNG运行一个测试_Java_Testng - Fatal编程技术网

Java 在套件中从testNG运行一个测试

Java 在套件中从testNG运行一个测试,java,testng,Java,Testng,我的test.xml文件如下所示 <suite name="suitename"> <test name="testname1"> <classes> <class name="com.org.test1" /> </classes> </test> <test name="testname2"> <classes> &

我的test.xml文件如下所示

<suite name="suitename">

<test name="testname1">
    <classes>
        <class
            name="com.org.test1" />
    </classes>
</test>
<test name="testname2">
    <classes>
        <class
            name="com.org.test2" />
    </classes>
</test>

我尝试使用命令行
java org.testng test.xml-testname testname2
来运行第二个类。但是,它运行这两个测试

如何解决这个问题


下面是从命令提示符下的testng.xml执行所需测试的命令

  java -cp ".\bin;.\lib\*;" org.testng.TestNG testng.xml -testnames Test1
我希望您使用了调用defult套件的-testname

  Usage: <main class> [options] The XML suite files to run
Options:
-configfailurepolicy
   Configuration failure policy (skip or continue)
-d
   Output directory
-dataproviderthreadcount
   Number of threads to use when running data providers
-excludegroups
   Comma-separated list of group names to  exclude
-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
-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
-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
用法:[选项]要运行的XML套件文件
选项:
-配置失败策略
配置失败策略(跳过或继续)
-d
输出目录
-dataproviderthreadcount
运行数据提供程序时要使用的线程数
-排除群
要排除的组名的逗号分隔列表
-团体
要运行的组名的逗号分隔列表
-朱尼特
JUnit模式
默认值:false
-听众
.class文件列表或实现ITestListener或
ISuiteListener
-方法
试验方法的逗号分隔
默认值:[]
-方法选择器
实现IMethodSelector的.class文件列表或类名列表
-混合的
混合模式-自动检测当前测试的类型并使用
合适的跑步者
默认值:false
-对象工厂
.class文件列表或类名列表
ITestRunnerFactory
-平行的
并行模式(方法、测试或类)
可能值:[测试、方法、类、实例、无、真、假]
-港口
港口
-记者
自定义报表侦听器的扩展配置
-suitename
测试套件的默认名称(如果套件定义文件或
源代码
-suitethreadpoolsize
用于运行套件的线程池的大小
默认值:1
-测试类
测试类的列表
-测试罐
包含测试的jar文件
-测试名
测试的默认名称(如果未在suitedefinition文件或源中指定)
代码
-测试名
要运行的测试名称列表
-testrunfactory,-testrunfactory
用于创建测试的工厂
-线程数
并行运行测试时要使用的线程数
-usedefaultlisteners
是否使用默认侦听器
默认值:true
-日志,-详细
冗长程度
-xmlpathinjar
jar文件中xml文件的完整路径(仅在-testjar时有效)
(已指定)
默认值:testng.xml
谢谢,,
下面的Murali是从命令提示符下的testng.xml执行所需测试的命令

  java -cp ".\bin;.\lib\*;" org.testng.TestNG testng.xml -testnames Test1
我希望您使用了调用defult套件的-testname

  Usage: <main class> [options] The XML suite files to run
Options:
-configfailurepolicy
   Configuration failure policy (skip or continue)
-d
   Output directory
-dataproviderthreadcount
   Number of threads to use when running data providers
-excludegroups
   Comma-separated list of group names to  exclude
-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
-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
-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
用法:[选项]要运行的XML套件文件
选项:
-配置失败策略
配置失败策略(跳过或继续)
-d
输出目录
-dataproviderthreadcount
运行数据提供程序时要使用的线程数
-排除群
要排除的组名的逗号分隔列表
-团体
要运行的组名的逗号分隔列表
-朱尼特
JUnit模式
默认值:false
-听众
.class文件列表或实现ITestListener或
ISuiteListener
-方法
试验方法的逗号分隔
默认值:[]
-方法选择器
实现IMethodSelector的.class文件列表或类名列表
-混合的
混合模式-自动检测当前测试的类型并使用
合适的跑步者
默认值:false
-对象工厂
.class文件列表或类名列表
ITestRunnerFactory
-平行的
并行模式(方法、测试或类)
可能值:[测试、方法、类、实例、无、真、假]
-港口
港口
-记者
自定义报表侦听器的扩展配置
-suitename
测试套件的默认名称(如果套件定义文件或
源代码
-suitethreadpoolsize
用于运行套件的线程池的大小
默认值:1
-测试类
测试类的列表
-测试罐
包含测试的jar文件
-测试名
测试的默认名称(如果未在suitedefinition文件或源中指定)
代码
-测试名
要运行的测试名称列表
-testrunfactory,-testrunfactory
用于创建测试的工厂
-线程数
并行运行测试时要使用的线程数
-usedefaultlisteners
是否使用默认侦听器
默认值:true
-日志,-详细
冗长程度
-xmlpathinjar
jar文件中xml文件的完整路径(仅在-testjar时有效)
(已指定)
默认值:testng.xml
谢谢,,
Murali

如果我们想跳过测试用例任何部分的执行,我们可以在
testng.xml
文件中使用
exclude
标记。请查找以下跳过执行
testname1
test的xml文件:

<suite name="suitename">

<test name="testname1">
    <classes>
        <exclude
             name="com.org.test1" />
    </classes>
</test>
<test name="testname2">
    <classes>
        <class
             name="com.org.test2" />
    </classes>
</test>


希望这有帮助。

如果我们想跳过测试用例的任何部分,我们可以在
testng.xml
文件中使用
exclude
标记。请查找以下跳过执行
testname1
test的xml文件:

<suite name="suitename">

<test name="testname1">
    <classes>
        <exclude
             name="com.org.test1" />
    </classes>
</test>
<test name="testname2">
    <classes>
        <class
             name="com.org.test2" />
    </classes>
</test>


希望这有帮助。

Hi Murali,如果我使用-testnames,其他方法中的@BeforeSuite方法是否运行。似乎没有。嗨,Murali,如果我使用-testnames,那么其他方法中的@BeforeSuite方法是否运行。似乎没有。除了使用排除标记外,您还得到了问题的答案吗?除了使用排除标记外,您还得到了问题的答案吗?