<p>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?</p>

<p>ie </p>

<pre><code>[Test]
public void ShouldValidateUserNameIsLessThan100Characters() {}
</code></pre>

<p>verse </p>

<pre><code>[Test]
public void UserNameTestValidation1() {}
</code></pre>

[{'answer_id': 47477, 'author': 'zappan', 'author_id': 4723, 'author_profile': 'https://Stackoverflow.com/users/4723', 'pm_score': 1, 'selected': False, 'text': "<p>i wouldn't put conditions that test needs to meet in the name, because conditions may change in time. in your example, i'd recommend naming like</p>\n\n<pre><code>UserNameLengthValidate()\n</code></pre>\n\n<p>or</p>\n\n<pre><code>UserNameLengthTest()\n</code></pre>\n\n<p>or something similar to explain what the test does, but not presuming the testing/validation parameters.</p>\n"}, {'answer_id': 47478, 'author': 'Adrian Mouat', 'author_id': 4332, 'author_profile': 'https://Stackoverflow.com/users/4332', 'pm_score': 5, 'selected': True, 'text': '<p>The name of any method should make it clear what it does.</p>\n\n<p>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:</p>\n\n<pre><code>public void validateUserNameLength()\n</code></pre>\n\n<p>If the test changes, the name should be updated accordingly. </p>\n'}, {'answer_id': 47479, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 2, 'selected': False, 'text': "<p>I think if one can not find a good concise name for a test method it's a sign that design of this test is incorrect. Also good method name helps you to find out what happened in less time.</p>\n"}, {'answer_id': 47480, 'author': 'Rob Walker', 'author_id': 3631, 'author_profile': 'https://Stackoverflow.com/users/3631', 'pm_score': 0, 'selected': False, 'text': "<p>The name needs to matter within reason.  I don't want an email from the build saying that test 389fb2b5-28ad3 failed, but just knowing that it was a UserName test as opposed to something else would help ensure the right person gets to do the diagnosis.</p>\n"}, {'answer_id': 47507, 'author': 'flipdoubt', 'author_id': 470, 'author_profile': 'https://Stackoverflow.com/users/470', 'pm_score': 1, 'selected': False, 'text': '<p>Yes, the names of the code under test (methods, properties, whatever) can change, but I contend your existing tests should fail if the expectations change. That is the true value of having well-constructed tests, not perusing a list of test names. That being said, well named test methods are great tools for getting new developers on board, helping them locate "executable documentation" with which they can kick the tires of existing code -- so I would keep the names of test methods up to date just as I would keep the assertions made by the test methods up to date.</p>\n\n<p>I name my test using the following pattern. Each test fixture attempts to focus on one class and is usually name {ClassUnderTest}Test. I name each test method {MemberUnderTest}_{Assertion}.</p>\n\n<pre><code>[TestFixture]\npublic class IndexableFileTest\n{\n   [Test]\n   public void Connect_InitializesReadOnlyProperties()\n   {\n     // ...\n   }\n\n   [Test,ExpectedException(typeof(NotInitializedException))]\n   public void IsIndexable_ErrorWhenNotConnected()\n   {\n     // ...\n   }\n\n   [Test]\n   public void IsIndexable_True()\n   {\n     // ...\n   }\n\n   [Test]\n   public void IsIndexable_False()\n   {\n     // ...\n   }\n}\n</code></pre>\n'}, {'answer_id': 47539, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': 3, 'selected': False, 'text': "<p><strong>Very. Equally important as choosing good method and variable names.</strong><br>\nMuch more if your test suite is going to referred to by new devs in the future.</p>\n\n<p>As for your original question, definitely Answer1. Typing in a few more characters is a small price to pay for </p>\n\n<ul>\n<li>the readability. For you and others. It'll eliminate the 'what was I thinking here?' as well as 'WTF is this guy getting at in this test?'</li>\n<li>Quick zoom in when you're in to fix something someone else wrote</li>\n<li>instant update for any test-suite visitor. If done correctly, just going over the names of the test cases will inform the reader of the specs for the unit.</li>\n</ul>\n"}, {'answer_id': 47550, 'author': 'Lars Mæhlum', 'author_id': 960, 'author_profile': 'https://Stackoverflow.com/users/960', 'pm_score': 3, 'selected': False, 'text': '<p>Yes.</p>\n\n<pre><code> [Test]\n public void UsernameValidator_LessThanLengthLimit_ShouldValidate() {}\n</code></pre>\n\n<p>Put the test subject first, the test statement next, and the expected result last.<br>\nThat way, you get a clear indication of what it is doing, and you can easily sort by name :)</p>\n'}, {'answer_id': 47588, 'author': 'Quibblesome', 'author_id': 1143, 'author_profile': 'https://Stackoverflow.com/users/1143', 'pm_score': 2, 'selected': False, 'text': "<p>Yes, the whole point of the test name is that it tells you what doesn't work when the test fails.</p>\n"}, {'answer_id': 47627, 'author': 'JC.', 'author_id': 3615, 'author_profile': 'https://Stackoverflow.com/users/3615', 'pm_score': 0, 'selected': False, 'text': '<pre><code>[RowTest]\n[Row("GoodName")]\n[Row("GoodName2")]\npublic void Should_validate_username()\n{\n}\n\n[RowTest]\n[Row("BadUserName")]\n[Row("Bad%!Name")]\npublic void Should_invalidate_username()\n{\n}\n</code></pre>\n\n<p>This might make more sense for more complex types of validation really.</p>\n'}, {'answer_id': 47643, 'author': 'VanOrman', 'author_id': 4550, 'author_profile': 'https://Stackoverflow.com/users/4550', 'pm_score': 0, 'selected': False, 'text': '<p>Yes, they are.  I\'d personally recommend looking at <a href="http://www.ssw.com.au/ssw/Standards/Rules/RulesToBetterUnitTests.aspx" rel="nofollow noreferrer">SSW\'s rules to better unit tests</a>.  It contains some very helpful naming guidelines.</p>\n'}, {'answer_id': 47650, 'author': 'marcospereira', 'author_id': 4600, 'author_profile': 'https://Stackoverflow.com/users/4600', 'pm_score': 3, 'selected': False, 'text': '<p>Yes, the names are totally important, specially when you are running the tests in console or continuous integration servers. Jay Fields wrote a <a href="http://blog.jayfields.com/2008/05/testing-value-of-test-names.html" rel="nofollow noreferrer">post about it</a>.</p>\n\n<p>Moreover, put good test names with <a href="http://blog.jayfields.com/2007/06/testing-one-assertion-per-test.html" rel="nofollow noreferrer">one assertion per test</a> and your suite will give you great reports when a test fails.</p>\n'}, {'answer_id': 47825, 'author': 'Johan', 'author_id': 4804, 'author_profile': 'https://Stackoverflow.com/users/4804', 'pm_score': 1, 'selected': False, 'text': "<p>Having a very descriptive name helps to instantly see what is not working correctly, so that you don't actually need to look at the unit test code.\nAlso, a list of all the unit tests describes the intended behavior of the unit, and can be used (more or less) as documentation to the behavior of the unit under test.</p>\n\n<p>Note, this only works when unit tests are very specific and do not validate too much within one unit test. </p>\n\n<p>So for example:</p>\n\n<pre><code>[Test]\nvoid TestThatExceptionIsRaisedWhenStringLengthLargerThen100()\n\n[Test]\nvoid TestThatStringLengthOf99IsAccepted()\n</code></pre>\n"}, {'answer_id': 60230, 'author': 'flipdoubt', 'author_id': 470, 'author_profile': 'https://Stackoverflow.com/users/470', 'pm_score': 3, 'selected': False, 'text': '<p>In <a href="http://amazon.com/o/ASIN/0132350882" rel="noreferrer">Clean Code</a>, page 124, <a href="http://www.objectmentor.com/omTeam/martin_r.html" rel="noreferrer">Robert C. Martin</a> writes:</p>\n\n<blockquote>\n  <p>The moral of the story is simple: <em>Test code is just as important as production code.</em> It is not a second-class citizen. It requires thought, design, and care. It must be kept as clean as production code.</p>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/47475', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4642/']