“This Method Has a Constructor Name” Warning in Eclipse for Unit Tests
If you get annoyed when Eclipse alerts you about your unit tests that “This method has a constructor name”, you can set it to ignore these warnings in Window / Preferences / Java / Compiler / Error/Warnings - set “Methods with a Constructor Name” to “Ignore”.
It’s generally a bad idea to switch off warnings but in this case I think the JUnit syntax is confusing Eclipse so it’s easier to just switch them off.
September 23rd, 2006 at 1:47 pm
Great posting on “This method has a constructor name” warning in Eclipse…It was really annoying and now I know I am not breaking some secret Java rule…
September 25th, 2006 at 1:08 pm
Thanks Sudhi.
I’m annoyed with myself that I didn’t make better notes when originally posting this - if you revisit would you mind posting a comment detailing the JUnit method that provoked this warning and the version of Eclipse you are using. I experienced this on Eclipse 3.1 and haven’t had the same problem with 3.2 so I’m guessing the problem has been fixed (although I can’t find a bug report describing it). Cheers.
February 20th, 2008 at 11:09 pm
I’m interested in what is missing that it feels it has to make that comment for, ya know? Usually Eclipse has a pretty good idea what’s going on, so it makes me feel like I’m missin’ something.
February 20th, 2008 at 11:13 pm
Ah, in my case it was because I was doin’ something that was syntactically correct, wouldn’t cause any errors, but wasn’t necessary. Which is to say, putting “void” before the return.
May 19th, 2008 at 4:25 am
Hi my name is Alan and I´m from Argentina
I never post in a forum, this is my first time.
Trying to resolve this problem I find this forum and I thought I´ll be a good idea post my experience.
Tchal has reason. The problem with thw warning is about the standard of Oriented Object Programing. Eclipse alerts you, because you are using the same name of the class for a method wich is not a constructor. Eclipse knows that because the sign of the method is diferent from a constructors sign method. Then you must allways use the name of the class only for a constructor method without putting the return value on the sign.