持续集成 使用 testNG 遇见的一个怪问题,无法使用 Ant 运行了,但使用 testng.xml 是正常的

曾晖斌 · 2015年09月16日 · 最后由 honglinwang 回复于 2019年10月08日 · 2418 次阅读

# 问题如下
这个最近修改了各种类型的报告,再一次修改中不知道怎么了,就出现以下问题:
右键 testng.xml 文件 run as 是可以成功的,但在 build.xml 使用 ant 的方法就不行,具体报错在最后,报错的那行我也标记出来了,已经搞了两天了。

<target name="test">
        <testng classpathref="ant-appium.classpath"
            outputdir="test-results"
            haltonfailure="true"
            useDefaultListeners="false"
 -----76行---           listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
      <xmlfileset dir="." includes="testng.xml"/>
      <sysproperty key="org.uncommons.reportng.title" value="Xiaomi Test Report"/>
     </testng>  
    </target>

上面是 build.xml 的运行的代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none" preserve-order="true" >
  <parameter name="username" value="13812349876" />
  <parameter name="" value="4558" />
  <parameter name="param" value="param" />
  <test name="Test">
    <classes>
      <class name="com.XiaomiTestCase.XiaoMiSmoke"/>
        <include name="testLogin"/>
        <include name="testMyWallet"/>
    </classes>

</test> <!-- Test -->
</suite> <!-- Suite -->

这个是 testng.xml 文件

Buildfile: E:\测试文档\appium测试工程\ant-appium\build.xml
test:
   [testng] java.io.FileNotFoundException: E:\测试文档\appium测试工程\ant-appium\testng.xml (ϵͳ�Ҳ���ָ�����ļ���)
   [testng]     at java.io.FileInputStream.open0(Native Method)
   [testng]     at java.io.FileInputStream.open(FileInputStream.java:195)
   [testng]     at java.io.FileInputStream.<init>(FileInputStream.java:138)
   [testng]     at java.io.FileInputStream.<init>(FileInputStream.java:93)
   [testng]     at org.testng.xml.Parser.parse(Parser.java:167)
   [testng]     at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
   [testng]     at org.testng.TestNG.run(TestNG.java:1030)
   [testng]     at org.testng.TestNG.privateMain(TestNG.java:1364)
   [testng]     at org.testng.TestNG.main(TestNG.java:1333)
   [testng] Usage: <main class> [options] The XML suite files to run
   [testng]   Options:
   [testng]     -configfailurepolicy               Configuration failure policy (skip or
   [testng]                                        continue)
   [testng]     -d                                 Output directory
   [testng]     -dataproviderthreadcount           Number of threads to use when running
   [testng]                                        data providers
   [testng]     -excludegroups                     Comma-separated list of group names to 
   [testng]                                        exclude
   [testng]     -groups                            Comma-separated list of group names to be
   [testng]                                        run
   [testng]     -junit                             JUnit mode
   [testng]                                        Default: false
   [testng]     -listener                          List of .class files or list of class
   [testng]                                        names implementing ITestListener or
   [testng]                                        ISuiteListener
   [testng]     -methods                           Comma separated of test methods
   [testng]                                        Default: []
   [testng]     -methodselectors                   List of .class files or list of class
   [testng]                                        names implementing IMethodSelector
   [testng]     -mixed                             Mixed mode - autodetect the type of
   [testng]                                        current test and run it with appropriate runner
   [testng]                                        Default: false
   [testng]     -objectfactory                     List of .class files or list of class
   [testng]                                        names implementing ITestRunnerFactory
   [testng]     -parallel                          Parallel mode (methods, tests or classes)
   [testng]     -port                              The port
   [testng]     -reporter                          Extended configuration for custom report
   [testng]                                        listener
   [testng]     -suitename                         Default name of test suite, if not
   [testng]                                        specified in suite definition file or source code
   [testng]     -suitethreadpoolsize               Size of the thread pool to use to run
   [testng]                                        suites
   [testng]                                        Default: 1
   [testng]     -testclass                         The list of test classes
   [testng] [TestNG] [ERROR] No test suite found. Nothing to run
   [testng]     -testjar                           A jar file containing the tests
   [testng]     -testname                          Default name of test, if not specified in
   [testng]                                        suitedefinition file or source code
   [testng]     -testnames                         The list of test names to run
   [testng]     -testrunfactory, -testRunFactory   The factory used to create tests
   [testng]     -threadcount                       Number of threads to use when running
   [testng]                                        tests in parallel
   [testng]     -usedefaultlisteners               Whether to use the default listeners
   [testng]                                        Default: true
   [testng]     -log, -verbose                     Level of verbosity
   [testng]     -xmlpathinjar                      The full path to the xml file inside the
   [testng]                                        jar file (only valid if -testjar was
   [testng]                                        specified)
   [testng]                                        Default: testng.xml

BUILD FAILED
\ant-appium\build.xml:76: No tests were run

Total time: 598 milliseconds

共收到 3 条回复 时间 点赞

有可能是因为路径中的中文编码吗?异常信息中的 FileNotFound 那一行的 message 是乱码。如果需要的的话,统一成 UTF-8。

#1 楼 @newbee testng.xml 是没有中文的,那个报错的应该是中文的 我都不知道哪出来的,报错的路径中文件是存在的,怎么提示 FileNotFound

仅楼主可见
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册