One Click Test Conversions
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!