Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are unit-test names important?

Tags:

unit-testing

If unit-test names can become outdated over time and if you consider that the test itself is the most important thing, then is it important to choose wise test names?

ie

[Test]
public void ShouldValidateUserNameIsLessThan100Characters() {}

verse

[Test]
public void UserNameTestValidation1() {}
like image 829
Xian Avatar asked Sep 06 '08 13:09

Xian


2 Answers

The name of any method should make it clear what it does.

IMO, your first suggestion is a bit long and the second one isn't informative enough. Also it's probably a bad idea to put "100" in the name, as that's very likely to change. What about:

public void validateUserNameLength()

If the test changes, the name should be updated accordingly.

like image 59
Adrian Mouat Avatar answered Oct 25 '22 15:10

Adrian Mouat


Yes, the names are totally important, specially when you are running the tests in console or continuous integration servers. Jay Fields wrote a post about it.

Moreover, put good test names with one assertion per test and your suite will give you great reports when a test fails.

like image 44
marcospereira Avatar answered Oct 25 '22 16:10

marcospereira