|
| 1 | +--- |
| 2 | +applyTo: |
| 3 | + - "src/Nethermind.Arbitrum.Test/**/*.cs" |
| 4 | + - "**/Test/**/*.cs" |
| 5 | + - "**/*Tests.cs" |
| 6 | + - "**/*Test.cs" |
| 7 | +--- |
| 8 | + |
| 9 | +# Test Code Review Instructions |
| 10 | + |
| 11 | +## Test Naming Convention (CRITICAL - ALWAYS ENFORCE) |
| 12 | + |
| 13 | +**Pattern: `MethodName_Condition_ExpectedResult`** |
| 14 | + |
| 15 | +Every test method MUST have exactly THREE parts separated by underscores: |
| 16 | +1. Method/feature being tested |
| 17 | +2. State/condition/input |
| 18 | +3. Expected behavior/result |
| 19 | + |
| 20 | +### CORRECT Examples (approve these patterns) |
| 21 | +```csharp |
| 22 | +GetBalance_ValidAccountAndEnoughGas_ReturnsBalance |
| 23 | +GetBalance_InsufficientGas_ThrowsOutOfGasException |
| 24 | +GetBalance_NonExistentAccount_ReturnsZero |
| 25 | +DigestMessage_ValidMessage_ProducesBlock |
| 26 | +ParseInput_MalformedData_ThrowsDecodingException |
| 27 | +``` |
| 28 | + |
| 29 | +### WRONG Examples (REJECT and request fix) |
| 30 | +```csharp |
| 31 | +// Missing condition part |
| 32 | +GetBalance_ReturnsBalance // REJECT: missing condition |
| 33 | +TestGetBalance // REJECT: not following pattern |
| 34 | +
|
| 35 | +// Informal/verbose language |
| 36 | +GetBalance_DoesntHaveEnoughBalance_Fails // REJECT: use "InsufficientBalance" |
| 37 | +GetBalance_WhenAccountDoesNotExist_Returns0 // REJECT: use "NonExistentAccount" |
| 38 | +
|
| 39 | +// Extra prefixes |
| 40 | +Should_GetBalance_WhenValid_ReturnBalance // REJECT: no "Should" prefix |
| 41 | +Test_GetBalance_Returns_Value // REJECT: no "Test" prefix |
| 42 | +
|
| 43 | +// Vague naming |
| 44 | +BalanceTest // REJECT: not descriptive |
| 45 | +TestMethod1 // REJECT: meaningless name |
| 46 | +``` |
| 47 | + |
| 48 | +### Naming Guidelines |
| 49 | + |
| 50 | +**For conditions, use concise terms:** |
| 51 | +- `ValidInput`, `InvalidInput`, `MalformedData` |
| 52 | +- `EnoughGas`, `InsufficientGas`, `ZeroGas` |
| 53 | +- `ExistingAccount`, `NonExistentAccount` |
| 54 | +- `EmptyArray`, `NullParameter`, `ZeroValue` |
| 55 | + |
| 56 | +**For results, use action verbs:** |
| 57 | +- `ReturnsValue`, `ReturnsZero`, `ReturnsNull`, `ReturnsEmpty` |
| 58 | +- `ThrowsException`, `ThrowsArgumentException` |
| 59 | +- `ProducesBlock`, `UpdatesState`, `EmitsEvent` |
| 60 | +- `Succeeds`, `Fails` |
| 61 | + |
| 62 | +## Test Structure (AAA Pattern) |
| 63 | + |
| 64 | +Require clear Arrange/Act/Assert sections: |
| 65 | + |
| 66 | +```csharp |
| 67 | +[Test] |
| 68 | +public void GetBalance_ValidAccount_ReturnsBalance() |
| 69 | +{ |
| 70 | + Address account = new("0x123..."); |
| 71 | + UInt256 expectedBalance = 1000; |
| 72 | + |
| 73 | + UInt256 result = sut.GetBalance(account); |
| 74 | + |
| 75 | + Assert.That(result, Is.EqualTo(expectedBalance)); |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +## Assertion Rules (CRITICAL) |
| 80 | + |
| 81 | +**REJECT** these assertion patterns: |
| 82 | +```csharp |
| 83 | +// WRONG - no range comparisons |
| 84 | +Assert.That(value, Is.GreaterThan(0)); |
| 85 | +Assert.That(value, Is.LessThan(100)); |
| 86 | +Assert.That(value, Is.AtLeast(1)); |
| 87 | + |
| 88 | +// CORRECT - exact values only |
| 89 | +Assert.That(value, Is.EqualTo(42)); |
| 90 | +Assert.That(value, Is.EqualTo(expectedValue)); |
| 91 | +``` |
| 92 | + |
| 93 | +**Flag** tests with: |
| 94 | +- Multiple unrelated assertions |
| 95 | +- Branching logic (if/switch) |
| 96 | +- Shared mutable state between tests |
| 97 | +- Dependencies on test execution order |
| 98 | + |
| 99 | +## Test Organization |
| 100 | + |
| 101 | +**Flag** these patterns: |
| 102 | +- `[SetUp]` or `[TearDown]` methods (prefer self-contained tests) |
| 103 | +- Private helper methods (should be in test infrastructure) |
| 104 | +- Test classes with dependencies on other test classes |
| 105 | + |
| 106 | +## Type Declarations in Tests |
| 107 | + |
| 108 | +Same as production code - **REJECT** `var` keyword: |
| 109 | + |
| 110 | +```csharp |
| 111 | +// CORRECT |
| 112 | +IWorldState worldState = TestWorldStateFactory.CreateForTest(); |
| 113 | +Address account = new("0x123..."); |
| 114 | + |
| 115 | +// WRONG |
| 116 | +var worldState = TestWorldStateFactory.CreateForTest(); |
| 117 | +var account = new Address("0x123..."); |
| 118 | +``` |
0 commit comments