Quick Fix for JUnit
The TestNG IDEA plug-in has an interesting feature that I just implemented in the Eclipse plug-in: if you press Ctrl-1 (Quick Fix) on a JUnit test class, the plug-in will give you the option to convert it to TestNG, either with JDK5 annotations:

or JavaDoc annotations:

The operations performed by this extension are very simple:
- Remove all the JUnit imports
- Add TestNG imports (for JDK5 annotations only)
- Import
AssertJUnit - Remove
extends TestCase - Add
@Testannotations on top of any method that starts with “test” - Add
@Configuration(beforeTestMethod = true)on top ofsetUp() - Add
@Configuration(afterestMethod = true)on top oftearDown() - Add
@Factoryon top ofsuite()
And that’s it! These are fairly simple changes and again, I am struck at how intuitive the Eclipse API is. Manipulating the AST is a real pleasure and as you can see above, the ASTRewriter gives you a lot of goodies for free, among which unlimited undo and a nice preview window.
Comments (4)
Can you do it on a whole package tree? Might make it a bit easier to convert a thousand-odd test cases. Certainly, this sort of support would assist people looking to experiment with or migrate to TestNG. Quite a good idea.
Make it an ANT task. :-)
Sir Otaku, You give me Java project!
Still getting some of that "Sit Otaku" project request spam... good luck with that. TestNG looks great, I was moderately happy with JUnit for many years, but since you have been pimping TestNG, my subconcious has come up with all sorts of problems with my junit code, and am feeling the need to bite the bullet. Damn you ! Things like this that ease the way are very very much appreciated.