Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I document my unit test methods?

As it happens with private methods, unit test methods documentation can only be seen by who has access to the source code. Is it worth the effort spent on it?

By documentation I mean something like (but more descriptive):

/// <summary>
///A test for SomeClass.SomeMethod
///</summary>
[TestMethod()]
public void SomeMethodTest()
{
}
like image 912
Jader Dias Avatar asked Dec 08 '09 18:12

Jader Dias


4 Answers

Unit tests should aim to be self descriptive, but there will always be cases where this goal cannot be achieved and thus description of what has been written is due.

In other words, try to make your unit tests so they don't need documentation, but if they need it, write it!

like image 146
Vinko Vrsalovic Avatar answered Nov 16 '22 00:11

Vinko Vrsalovic


I would rather be inclined to saying that you should name your test method in a manner that is expressive with regards to what it tests: SomeMethodWillBehaveThisWayWhenCalledWithTheseParameters() although some people may find that controversial.

like image 39
Klaus Byskov Pedersen Avatar answered Nov 16 '22 00:11

Klaus Byskov Pedersen


Oh yes!

Even if "who has access to the source code" is never ever going to be anyone else than you, it wont be the same you that look at it in a year (or even a month from now), trust me on that one :-)

like image 22
Per Wiklander Avatar answered Nov 16 '22 00:11

Per Wiklander


You should document all code.

For unit tests, I usually say what I'm testing, and how it's tested. Putting "Test for Class.someMethod" is not very helpful.

like image 25
Ben S Avatar answered Nov 15 '22 23:11

Ben S