10 DAYS AGOย โ€ขย 1 MIN READ

(#4) One (simple) trick to write BETTER tests ๐Ÿงช

profile

pills.dev ๐Ÿ’Š weekly coding tips & tricks

Join +2,660 software developers getting weekly tips covering security, quality and system design.

When we write software, it's extremely important to make it as easy to read as possible (by others or just us in the future).

The same principle applies to writing (unit) tests.

โ€‹

What can we do to make
unit tests
more readable? ๐Ÿ”

โ€‹

Follow the simple AAA pattern:

  1. Arrange - prepare the test and data
  2. Act - call the method under test
  3. Assert - verify results

โ€‹

The useful convention to apply this in the code is to use comments given / when / then as in the example below.

This approach will help you quickly understand what the test is all about.

Of course, there are many other good practices for writing tests, but... this is just a quick knowledge pill for you! ๐Ÿ’Š

โ€‹

Rate this email:

โ€‹GREAT ๐Ÿ˜ƒ | OKEY ๐Ÿ˜ | BAD ๐Ÿ˜Ÿ

โ€‹

Best wishes
Bartosz

pills.dev ๐Ÿ’Š weekly coding tips & tricks

Join +2,660 software developers getting weekly tips covering security, quality and system design.