有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我的测试。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 TestNG test.xml -testname testname2来运行第二个类。但是,它运行这两个测试

如何解决这个问题

谢谢


共 (2) 个答案

  1. # 1 楼答案

    如果我们想跳过测试用例任何部分的执行,我们可以在testng.xml文件中使用exclude标记。请查找以下跳过执行testname1测试的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>
    

    希望这有帮助

  2. # 2 楼答案

    下面是从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
    

    谢谢,, 穆拉里