I am a software engineer at Google on the Android project and the creator of the Java testing framework TestNG. When I'm not updating this weblog with various software-related posts or speaking at conferences, I am busy snowboarding, playing squash, tennis, golf or volleyball or scuba diving. Cedric is a DZone MVB and is not an employee of DZone and has posted 90 posts at DZone. You can read more from them at their website. View Full User Profile

One Click Test Conversions

01.05.2011
| 5929 views |
  • submit to reddit

If converting your tests to TestNG is one of your new year’s resolution, you are in luck. Introducing the improved JUnit to TestNG converter.

A couple of months ago, I gave a preview of the new features in the TestNG Eclipse plug-in and I observed that more and more people were converting their tests from JUnit 3 and JUnit 4 to TestNG. This latter was a surprise to me since I never really expected anyone would want to move away from JUnit 4 once they have migrated to it.

TestNG has long supported individual class conversions in the form of Quick Fixes:

I recently expanded this support and turned it into a full refactoring, which means that you can now apply it to entire packages, source folders or even projects.

To use it, install the latest TestNG Eclipse plug-in, open your Package Explorer and right click on either a package, a source folder or a project:

The refactoring wizard contains two pages.

The first one lets you customize the testng.xml that’s about to be generated (you can also choose not to generate one):

The next page shows you a view with all the changes that are about to be made to your source files. These changes are similar to the ones made with the Quick Fix except that they now apply to multiple files:

On this page, you can exclude certain files from being converted, and when you’re happy, press the Finish button.

Like all refactorings in Eclipse, you can undo your changes in one click if you change your mind:

In a next post, I’ll show how you can use this new functionality to help you check that your unit tests are as isolated as you think they are.

Now go ahead and convert your tests, that’s one less new year’s resolution you have to worry about!

From http://beust.com/weblog/2011/01/04/one-click-test-conversions

Published at DZone with permission of Cedric Beust, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Zqudlyba Navis replied on Wed, 2011/01/05 - 4:05am

Cédric, why is your Jan 2011 DZone profile still say you work for Google when you have since moved on to LinkedIn back in May 2010....unless you moved back to Google and you haven't told us ?

Raveman Ravemanus replied on Fri, 2011/01/07 - 7:11am

It would be cool is there was also convert to junit(or convert back) button, this way when your team doesnt want to install special plugin(which as we know cant be a part of eclipse) you can go back to using jUnit. I think jUnit is much better than TestNG tests with a static main methods in it(that is the way they by-pass not having the plugin).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.