TestNG: Eclipse confused by JUnit

Alexis Dufrenoy picture Alexis Dufrenoy · Feb 28, 2011 · Viewed 8k times · Source

I'm setting up tests with TestNG in an Eclipse project, but I get a strange error: When I try to generate a test class from a business class, I get a popup with a message saying "Grid not editable" (title) "The compilation unit is not compilable, or is not a sublcass of junit.framework.TestCase. Fix and tyr again" (body). Somehow, Eclipse seems to think I want to create JUnit classes, and I can't get why. Any clue?

Configuration:

  • Eclipse 3.6.0
  • TestNG 5.14.10

Answer

Alexis Dufrenoy picture Alexis Dufrenoy · Mar 1, 2011

Google CodePro Analytix, the newly open-sourced static analysis tool, is the cause of the problem. It creates a new default editor filter which tries to open each class which name ends with "Test" with its specific JUnit editor. The TestNG plugin for Eclipse, on the other side, generates test classes using the tested class name, with "Test" added at the end. So when you create a test class with the TestNG plugin, it's opened by default with CodePro Junit editor, which dispays an error popup saying the class is not a valid JUnit test class. Solution is to remove the editor filter in Eclipse Preferences:

Window -> Preferences ; General -> Editors -> File Associations

Select the *.java file type, pick Java Editor and click on the "Default" button.