What is the most accepted way to name a unit test method when the target has overloads. Consider these methods:
doSomething();
doSomething(String);
How would you name the corresponding test methods? Would this be the most accepted way?
testDoSomething();
testDoSomethingString();
A unit test method name is the first thing, anyone, trying to understand your code will read. It is important to write descriptive method names that help readers quickly identify the purpose of a test case. These method names communicate what the code does. A name should be concise, unambiguous, and consistent.
println("Integer "+i); } void method(int i){ System. out. println("in "+i); } public static void main(String a[]){ OverLoad m= new OverLoad(); m. method(2); //it calls method(int i) why? } }
Overloaded methods are differentiated by the number and the type of the arguments passed into the method. In the code sample, draw(String s) and draw(int i) are distinct and unique methods because they require different argument types.
Do whatever makes things more readable for you and your co-workers, if any. I think it depends on what your other tests for that class are, but based on those two methods, here is what I would do:
Test methods that test doSomething():
Test methods that test doSomething(String):
I don't use the test prefix anymore, as JUnit 4 doesn't require it. I just use the @Test annotation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With