Alex Rivera | Logout

Naming convention JUnit suffix or prefix Test

Asked 2010-06-30T06:04:41.570
67

Class under test MyClass.java JUnit test case name alternatives:

TestMyClass.java
MyClassTest.java

http://moreunit.sourceforge.net seems to use "Test" as prefix default but I have seen both uses. Both seems to be recognized when running the entire project as unit test in eclipse as it is the annotation inside classes that are parsed for @Test. I guess maven does the same thing.

Which is preferred?

Edit
Report

2 Answers

5

I prefer using the TestClassName syntax. When using the other syntax I have trouble identifying which is the test and which is the actual class in editors when I have both open. Having to look for the Last four letters in the name is tiresome and also these letters are not always displayed.

For me the other syntax leads to several wrong swapping´s between files every day and that is time consuming.

answered 2012-11-07T09:28:47.497
2

I think it is important you feel comfortable with your tests if you are working alone. But if you're in a group, you better sit down and get something fixed. I personally tend to use suffix for classes and prefix for methods and try to have my groups adapt to this convention.

answered 2012-11-07T09:33:38.790

Your Answer