What are the principles of good test design?

Answer

Principles for creating maintainable, valuable tests: (1) Test behavior, not implementation: tests should verify what the system does (from the caller's perspective), not how it does it internally. Refactoring should not break tests. (2) One assertion per test (ideally): each test verifies one concept — when it fails, you immediately know what's wrong. (3) DRY is secondary to clarity: test code prioritizes readability over DRY. Slight duplication is acceptable if it makes tests clearer. Use helper methods for complex setup, not at the cost of test readability. (4) Arrange-Act-Assert: consistent structure. (5) Descriptive naming: Given_ValidUser_When_Login_Then_ReturnsJwtToken() or login with valid credentials returns JWT token. Names document behavior. (6) Tests as documentation: a new developer should understand the system's behavior by reading the tests. (7) No logic in tests: avoid if/else, loops in tests — they can contain bugs themselves. (8) Independent and idempotent: run in any order, any number of times. (9) Test at the right level: don't use E2E tests for something unit tests can cover faster and more precisely. (10) Tests are production code: maintain them with the same care.