Test Organization and Naming Conventions

How to keep your tests tidy and clear

Posted by Rodrigo Castro on January 3, 2025

Good test organization makes it easy to find, run, and understand your tests.

📂 File and Folder Structure

  • Put tests in a separate project or folder (e.g. MyApp.Tests).
  • Mirror your code structure:
    If you have Calculator.cs, put CalculatorTests.cs in your test project.

📝 Naming Conventions

  • Test class: [ClassName]Tests (CalculatorTests)
  • Test method: Describe what it checks
    MethodName_ExpectedBehavior_Scenario()
1
2
3
4
5
[Fact]
public void Add_ReturnsSum_WhenCalledWithTwoNumbers()
{
    Assert.Equal(5, Add(2, 3));
}

🧑‍💻 Why This Matters

  • Makes it easy to see what the test checks.
  • Helps others understand test failures quickly.

💡 Try It!

Write a test method named
Multiply_ReturnsProduct_WhenNumbersArePositive()

Next: Mocking and test doubles!