Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recently came up with the following convention for naming my tests, their classes and containing projects in order to maximize their descriptivenes:</p> <p>Lets say I am testing the <em>Settings</em> class in a project in the <em>MyApp.Serialization</em> namespace.</p> <p>First I will create a test project with the <em>MyApp.Serialization.Tests</em> namespace. </p> <p>Within this project and of course the namespace I will create a class called <em>IfSettings</em> (saved as IfSettings.cs).</p> <p>Lets say I am testing the <em>SaveStrings()</em> method. -> I will name the test <em>CanSaveStrings()</em>.</p> <p>When I run this test it will show the following heading:</p> <p><em>MyApp.Serialization.Tests.IfSettings.CanSaveStrings</em></p> <p>I think this tells me very well, what it is testing.</p> <p>Of course it is usefull that in English the noun "Tests" is the same as the verb "tests".</p> <p>There is no limit to your creativity in naming the tests, so that we get full sentence headings for them. </p> <p>Usually the Testnames will have to start with a verb.</p> <p>Examples include: </p> <ul> <li>Detects (e.g. DetectsInvalidUserInput)</li> <li>Throws (e.g. ThrowsOnNotFound)</li> <li>Will (e.g. WillCloseTheDatabaseAfterTheTransaction)</li> </ul> <p>etc.</p> <p>Another option is to use "that" instead of "if". </p> <p>The latter saves me keystrokes though and describes more exactly what I am doing, since I don't know, <strong><em>that</em></strong> the tested behavior is present, but am testing <strong><em>if</em></strong> it is.</p> <p>[<em>Edit</em>]</p> <p>After using above naming convention for a little longer now, I have found, that the <em>If</em> prefix can be confusing, when working with interfaces. It just so happens, that the testing class <em>IfSerializer.cs</em> looks very similar to the interface <em>ISerializer.cs</em> in the "Open Files Tab". This can get very annoying when switching back and forth between the tests, the class being tested and its interface. As a result I would now choose <strong>That</strong> over <strong>If</strong> as a prefix.</p> <p>Additionally I now use - only for methods in my test classes as it is not considered best practice anywhere else - the "_" to separate words in my test method names as in:</p> <ul> <li>[Test] public void detects_invalid_User_Input() *</li> </ul> <p>I find this to be easier to read.</p> <p>[<em>End Edit</em>]</p> <p>I hope this spawns some more ideas, since I consider naming tests of great importance as it can save you a lot of time that would otherwise have been spent trying to understand what the tests are doing (e.g. after resuming a project after an extended hiatus).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload