Follow test-driven development with Arrange-Act-Assert pattern and meaningful assertions
Follow test-driven development practices with proper test structure and meaningful assertions.
This ensures code is testable and requirements are clear before implementation.
Structure tests clearly:
[Fact]
public void ProcessOrder_WithValidInput_ReturnsOrderId()
{
// Arrange
var service = new OrderService();
var order = new Order { CustomerId = 123, Amount = 99.99m };
// Act
var result = service.ProcessOrder(order);
// Assert
Assert.NotNull(result);
Assert.True(result.OrderId > 0);
}
Test meaningful behavior, not just serialization or data transfer:
// ❌ BAD - just testing serialization
Assert.Equal("John", user.Name);
// ✅ GOOD - testing business logic
Assert.True(order.CanBeShipped());
Assert.Equal(OrderStatus.Pending, order.Status);
Isolate units under test:
Test beyond the happy path:
For integration tests: