Test Desiderata

Strategies for Creating Comprehensive Yet Efficient Test Suites

View project on GitHub

Writable Tests

Table of Contents

Definition

Writable tests are tests that are easy to write and maintain, encouraging adoption and contribution to the test suite.

Also known as: Easy to Write (in the Test Desiderata 2.0 framework).

Part of a Larger Framework

This principle contributes to the macro goal of Minimize Total Cost of Ownership. Tests that are easy to write reduce the initial cost of creating tests and encourage developers to maintain comprehensive test coverage.

Related Properties:

  • Readable - Readable tests are also easier to write
  • Composable - Composability makes tests easier to write by reusing components
  • Automated - Automation reduces the cost of running writable tests

Learn more about how test properties work together in our framework overview.

Why Writability Matters

Adoption

Writable tests encourage developers to write tests, improving the overall coverage and quality of the test suite.

Productivity

Writable tests improve productivity by making it easier and faster to write and maintain tests.

Collaboration

Writable tests facilitate collaboration by making it easier for team members to contribute to the test suite.

Challenges of Writable Tests

Balancing Simplicity and Coverage

Ensuring that tests are simple and easy to write while providing adequate coverage can be challenging.

Consistency

Maintaining consistency in test structure and naming conventions requires effort and discipline.

Best Practices for Writable Tests

Provide Clear Guidelines

Provide clear and concise guidelines for writing tests to ensure consistency and ease of use.

  • Document best practices and naming conventions for writing tests.
  • Provide examples and templates to help developers write tests quickly and easily.

Use Simple Naming Conventions

Use simple and descriptive naming conventions to make tests easy to understand and write.

  • Follow a consistent naming convention that clearly expresses the test’s intent.
  • Avoid vague or generic names that do not convey the test’s purpose.

Keep Tests Simple

Keep tests simple and focused on a single responsibility to make them easier to write and maintain.

  • Break down complex tests into smaller, more manageable tests.
  • Avoid testing multiple behaviors or scenarios in a single test.

Practical Example

Writable tests can be implemented using various testing frameworks and tools. The key is to ensure that tests are easy to write and maintain, encouraging adoption and contribution to the test suite.

Common Pitfalls

Oversimplification

Avoid oversimplifying tests at the expense of adequate coverage and representativeness.

Inconsistent Guidelines

Do not use inconsistent or vague guidelines that do not clearly express the best practices for writing tests.

Conclusion

Writable tests are crucial for encouraging adoption, improving productivity, and facilitating collaboration. By following best practices and focusing on clear guidelines, simple naming conventions, and simplicity, teams can create writable tests that are easy to write and maintain.

Further Reading