Suddenly can't run TestNG tests from ant ([tes

2019-01-09 12:50发布

I am using ant and TestNG 6.1.1, and I had my tests working just fine yesterday. Today when I try to run the tests I get a NoClassDefFoundError involving com/beust/jcommander/ParamException. Here is the output:

[copy] Copying 1 file to /Users/djohnson/src/webapp/components/build/tmp
[testng] Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
[testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
[testng]    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[testng]    at java.security.AccessController.doPrivileged(Native Method)
[testng]    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[testng]    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[testng]    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[testng]    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[testng] The tests failed.

Here is the .xml file I'm using:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Single Method Suite">
  <test name="Single Method Test">
    <classes>
      <class name="DhcpTest">
        <methods>
          <exclude name=".*" />
          <include name="setGetEnabledTest" />
        </methods>
      </class>
    </classes>
  </test>
</suite>

I've also specified the complete path for the class with no luck. I've checked the classpath and everything seems fine, does anyone have any ideas on this?

标签: ant testng
7条回答
可以哭但决不认输i
2楼-- · 2019-01-09 13:00

I had this same problem with a non-Maven project. I retrieved the testng jar from Maven Central, but it didn't contain all of TestNG's dependencies. Downloading the jar directly from the TestNG site resolved the issue, as it contains the dependencies.

I should have paid more attention to the directions on TestNG's download page...

The latest version of TestNG can be downloaded from Maven Central or here for ant users.

查看更多
混吃等死
3楼-- · 2019-01-09 13:01

My ant start working when I have downloaded jcommandar jar from Maven repository and added it in my jar file

But This problem Starts coming with testng 6.8.5 version

查看更多
迷人小祖宗
4楼-- · 2019-01-09 13:02

May be testng.jar is not in classpath.

查看更多
干净又极端
5楼-- · 2019-01-09 13:03

jcommander.jar (e.g. jcommander-1.29.jar) should be present on fileset directory which is mentioned at build.xml

You can download it from: http://mvnrepository.com/artifact/com.beust/jcommander/1.27

OR,

JCommander should be inside testng.jar during using ant. Your testng.jar file might be corrupted, so please replace old testng.jar by new one.

查看更多
欢心
6楼-- · 2019-01-09 13:03

The problem here is that certain versions of the testNG jar do not have the jcommander jar code inside of them. As a result, you have to add the classpath to the Jcommander jar separately.

Adding the Jcommander jar to your classpath when you run it will fix the problem, hopefully

查看更多
地球回转人心会变
7楼-- · 2019-01-09 13:08

If you're using ant, JCommander should be inside testng.jar, so I'm thinking your testng.jar file might be corrupt.

查看更多
登录 后发表回答