Naming convention JUnit suffix or prefix Test [closed]
Another argument for suffix - at least in english language:
A class usually represents a noun, it is a model of a concept. An instance of one of your tests would be a 'MyClass test'. In contrast, a method would model some kind of action, like 'test [the] calculate [method]'.
Because of this, I'd always use the 'suffix' for test classes and the prefix for test methods:
the MyClass test --> MyClassTest
test the calculate method --> testCalculate()
I prefer to use the suffix - it means that looking down the list of files in a directory is simpler: you don't have to mentally ignore the first four letters to get to something meaningful. (I'm assuming you have the tests in a different directory to the production code already.)
It also means that when you use Open Type (Ctrl-T) in Eclipse, you end up seeing both the production code and its test at the same time... which is also a reminder if you don't see a test class :)
Prior to JUnit 4 it was common to name your test classes SomethingTest and then run JUnit across all classes matching *Test.java
. These days annotation driven JUnit 4, you just need to annotate your test methods with @Test
and be done with it. Your test classes are probably going to be under a different directory structure than your actual source (source in src/
test classes in test/
) so these days prefixes/suffixes are largely irrelevant.