Making tests easy to understand
Using descriptive test names is probably the single best thing you can do to improve your tests. I like to name my tests using simple sentences whenever possible. For example, one of the earliest tests we created is called "Test will pass without any confirms"
and looks like this:
TEST("Test will pass without any confirms")
{
}
A good pattern to follow is this:
<object><does something><qualification>
Each of the three sections should be replaced with something specific to what you’re doing. For the example just given, <object>
is Test
, <does something>
is will pass
, and <qualification>
is without
any confirms
.
I don’t always follow this pattern, especially when testing an object or a type for several different and related results. For example, a simple test immediately following the previous test looks like this:
TEST("Test bool confirms")
{
...