My JCommander & TestNG Conflict

336 views
Skip to first unread message

Steve Ramage

unread,
Oct 20, 2012, 10:43:46 PM10/20/12
to jcomm...@googlegroups.com

 Hello,

 

I recently tried to switch a project from JUnit to TestNG, unfortunately my Tests all broke in a pecular way. Namely they through ParameterExceptions when they didn't before. Upon closer inspection it appears that the TestNG / Eclipse plugin loads it's own internal version of JCommander up and then uses that. This causes my own build of JCommander, which has some additional support for things not yet in JCommander to break horribly. 
 

System.out.println("Location:" + this.getClass().getClassLoader().getResource("com/beust/jcommander/JCommander.class"));

 

in TestNG to say:

 

Location:jar:file:/opt/eclipse/plugins/org.testng.eclipse_6.7.0.20120825_1316/lib/testng.jar!/com/beust/jcommander/JCommander.class

 

In JUnit it says:

 

Location:jar:file:/home/sjr/git/AutomaticConfiguratorLibrary/lib/jcommander.jar!/com/beust/jcommander/JCommander.class

 

Thoughts:

 

 

Cédric Beust ♔

unread,
Oct 20, 2012, 11:05:48 PM10/20/12
to jcomm...@googlegroups.com
Hi Steve,

It's a bit of a sticky situation and there is no easy way out. One workaround would be:
  • Use the "barebones" testng.jar of the distribution (which contains no dependencies).
  • Configure your Eclipse project to use the project's testng.jar.
  • Manually add the .jar dependencies that testng.jar needs (minus jcommander.jar, which you already have on your classpath).
Can you try that? If not, there are a couple of other options.


-- 
Cédric

Steve Ramage

unread,
Oct 20, 2012, 11:17:52 PM10/20/12
to jcomm...@googlegroups.com

Will this work in general?  Specifically the class path in question I think is just the runtime class path, so if I want to use TestNG in general where I don't have JCommander it seems like it would be unavailable. 

I'm also not sure about how to just replace this, should I just go into the eclipse installation and replace testng.jar with the downloadable one, and find the dependencies somehow (I assume Maven will tell me but I'm not a maven user).

 

I suppose another option would be to just replace the class files in my plugin with my version, but that might also be brittle.

 

 

Steve Ramage

Cédric Beust ♔

unread,
Oct 20, 2012, 11:23:43 PM10/20/12
to jcomm...@googlegroups.com

In the TestNG settings, there is a check box "Use the projects testng.jar", no need to modify the installation.

Steve Ramage

unread,
Oct 20, 2012, 11:29:50 PM10/20/12
to jcomm...@googlegroups.com

 What is the bare bones version of testNG, I downloaded the zip off the website, but it also includes jcommander internally.

Cédric Beust ♔

unread,
Oct 20, 2012, 11:31:45 PM10/20/12
to jcomm...@googlegroups.com

Steve Ramage

unread,
Oct 20, 2012, 11:39:06 PM10/20/12
to jcomm...@googlegroups.com

Hmmmm that seems to have worked, there were no other dependencies, it seems to work as is thank you.

Cédric Beust ♔

unread,
Oct 20, 2012, 11:42:06 PM10/20/12
to jcomm...@googlegroups.com

Good to hear. Note that you might encounter ClassNotFoundExceptions when you start running tests that exercise different code paths in TestNG, but you know what to do then...

Reply all
Reply to author
Forward
0 new messages