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 haveCalculator.cs
, putCalculatorTests.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!