0

In eclipse,the project runs well,get the correct answer.

When run from command line,project start well,but runs in mistakes.Such as code :

@Override
public void onTestFailure(ITestResult result)
{
    ITestContext Itc = result.getTestContext();
    StringBuilder caseStr = new StringBuilder("<tr bgcolor=\"#FF0000\"><td>");
    caseStr.append(getTestName(result));
    caseStr.append("</td><td>失败</td><td>");
    caseStr.append(s_errorInfor + "</td></tr>");
    appendToResFile(caseStr.toString());
}

The line : result.getTestContext() calls exception. Take this code away,it will run well:

F:\AppJavaProject\autoTest\autoTestV1\cmd>java org.testng.TestNG testMainXML.xml
[TestNG] Running:
F:\AppJavaProject\autoTest\autoTestV1\cmd\testMainXML.xml


===============================================
ssmSuite
Total tests run: 6, Failures: 6, Skips: 0
===============================================

It confused me three days,please help!

Command line bat file:

set LIB=F:\AppJavaProject\autoTestV1\cmd
set NGLIB=F:\AppJava\testNG_libs\libs
set JAVA_CLIENT=F:\AppJava
set CLASSPATH=%NGLIB%\*;%JAVA_CLIENT%\java-client-5.0.0-BETA1.jar;autoTestV1.jar;

java org.testng.TestNG testMainXML.xml

results:

F:\AppJavaProject\autoTest\autoTestV1\cmd>java org.testng.TestNG     testMainXML.xml
[TestNG] Running:
F:\AppJavaProject\autoTest\autoTestV1\cmd\testMainXML.xml

Exception in thread "main" java.lang.NoSuchMethodError: org.testng.ITestResult.getTestContext()Lorg/
testng/ITestContext;
at autoTestV1.ResultReport.onTestFailure(ResultReport.java:146)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1796)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1780)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1230)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.runWorkers(TestRunner.java:1147)
at org.testng.TestRunner.privateRun(TestRunner.java:749)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
at org.testng.SuiteRunner.run(SuiteRunner.java:223)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1039)
at org.testng.TestNG.runSuitesLocally(TestNG.java:964)
at org.testng.TestNG.run(TestNG.java:900)
at org.testng.TestNG.privateMain(TestNG.java:1182)
at org.testng.TestNG.main(TestNG.java:1146)

F:\AppJavaProject\autoTest\autoTestV1\cmd>
ssm
  • 21
  • 5
  • What is the exception? – Tim Biegeleisen Feb 24 '17 at 04:38
  • Exception in thread "main" java.lang.NoSuchMethodError: org.testng.ITestResult.getTestContext()Lorg/ testng/ITestContext; at autoTestV1.ResultReport.onTestFailure(ResultReport.java:146) at org.testng.internal.Invoker.runTestListeners(Invoker.java:1796) at org.testng.internal.Invoker.runTestListeners(Invoker.java:1780) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1230) – ssm Feb 24 '17 at 06:07
  • Check your TestNG version in both cases. I think the one you use with the command line is too old. – juherr Feb 24 '17 at 09:27
  • Could you confirm if the issue is reproduced using `java -cp "" org.testng.TestNG testMainXML.xml`. Do take a look at http://stackoverflow.com/a/11897452/1746118 – Naman Feb 24 '17 at 12:27
  • 1.To friend "juherr":TestNG version is OK. 2.To friend "nullpointer":I can run TestNG from command line,it can runs for normal tests,but after I rewrite the testListener,it can't run well. – ssm Feb 27 '17 at 01:25
  • show your testMainXML.xml, probably there is your mistake. – underwater ranged weapon Feb 28 '17 at 08:35

0 Answers0