Do you follow the standard naming conventions for tests?

Last updated by Tiago Araújo [SSW] 5 months ago.See history

This rule has been archived

Ensuring a consistent and organized approach to testing is pivotal in any development process. Do you adhere to the established standard naming conventions for tests? Let's explore the importance of this practice and its impact on the efficiency and clarity of your testing procedures.

As well as keeping your code tidy, using this naming convention also allows you to use TestDriven.Net's 'Go To Test/Code' command. This navigates between your tests and code under test (and back). This is something that test-driven developers end up doing a lot. Screen captures at

  • Jamie Cansdale
Test Object Recommended Style Example
Project Name Tests.[Testtypes].Projectname Tests.Unit.Common,Tests.Unit.WebFrontend,Test.Integration.MainWCFService
Tests.Functional.SilverlightUI, Tests.Functional.WebUI *
Test Fixture Name [Type]Tests OrdersTests, CustomerTests, DeveloperTests
Test Case [Function]Test NullableIntTryParse_NumberIsValid1_Return1, StringHelperEncodeTo64_EncodeAndUnencodeString_ReturnSameString
Set Up SetUp
Tear Down TearDown

* Test types are categorized into "Unit" "Integration" or "Functional" tests, as explained in "the different types of test you can have"

The main reason why we are categorizing tests is so that we can run different test suites. Eg.

  • Unit tests on Gated Checkin
  • Integration tests after each check in on the build server
  • All tests including the functional tests in the nightly build

Samples for Naming of test projects

Test.Unit.WebUI: This test project, tests the WebUI project, and is independent of external resources. That means all tests must pass.

Test.Integration.WebUI: This test project tests the WebUI and depends on other external resources (Eg. probably needs a database, web services, etc.). That means if any external resource is unavailable, the tests will fail.

Tests.Functional.SilverlightUI: Tests the Silverlight UI from an end-user perspective by clicking around in the application

Figure: Good example - Naming for a Unit Test Project

Samples Naming of test methods

 public void Test_Client()

Bad example: There is no way to guess what this test does; you have to read the source

 public void PubSubServiceConnectTest_AuctionOk_AuctionInfoReturned()

Good example: We are testing PubSubService.Connect under the scenario that the "Auction status is OK" with an expected behaviour that data is returned

Sample Code for Integration Tests

using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using NUnit.Framework;
using SSW.NetToolKit.BusinessService;
using SSW.NetToolKit.DataAccess;
namespace SSW.NETToolkit.IntegrationTests
  Public class CustomerTests
    BusinessRules business=new BusinessRules(); 
    public void OrderTotal_SimpleExampleInput()
        decimal calculatedGrandTotal = business.CalculateOrderGrandTotal(10248);
        int expected = 440;
        Assert.AreEqual(expected, calculatedGrandTotal, "Calculated grand total didn't match the expect
    public void OderTotal_Discounts()
        decimal calculatedGrandTotal = business.CalculateOrderGrandTotal(10260);
        decimal expected = 1504.65m;
        Assert.AreEqual(expected, calculatedGrandTotal, "Calculated grand total didn't match the expecte
    public void RoundingTest_RoundUp()
        Assert.AreEqual(149.03, business.ApplyRounding(149.0282m), "Incorrect rounding rules applied for
    public void RoundingTest_RoundDown()
        Assert.AreEqual(149.02, business.ApplyRounding(149.0232m), "Incorrect rounding rules applied 
    public void RoundingTest_NoRoundingNeeded()
        Assert.AreEqual(149.02, business.ApplyRounding(149.02m), "Incorrect rounding rules applied for 
    public void RoundingTest_BorderCondition()
        Assert.AreEqual(149.02, business.ApplyRounding(149.025m), "Incorrect rounding rules applied for

Figure: This rule is consistent with the Visual Studio default

Tip: You can create a test project using the Unit Test Wizard: Test > Add New Test

Figure: Unit Test Wizard 1

Figure: Unit Test Wizard 2

We open source. Powered by GitHub