Skip to content

Readable tests #45

@sebastian-hans-bbv

Description

@sebastian-hans-bbv

Abstract

Do you like reading tests? I like reading tests. Tests tell you what the developers cared about. Good tests also tell you what the software is supposed to do. 😁 And very good tests even tell you why. In this post, I will show how you can get more out of your tests with a few simple tricks.

Scope

This is about how to write tests that are themselves readable and understandable. It is not about selecting what to test, and it is not about designing code to be testable.

Outline

  • Example of a bad test case: badly named, Spaghetti code. I will use each of the tricks on this example in turn.
  • Trick 1: Test one thing in each test case
  • Trick 2: Naming in „X should Y when Z“ form
  • Trick 3: Arrange, Act, Assert
  • Trick 4: All relevant test data in the test case
  • Trick 5: Factories for test data
  • Trick 6: Custom assertions
  • The final result: A set of clean and readable test cases

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions