Write tests with realistic data.

Use detailed examples with precise answers.

When writing automated tests, it’s simply not enough to have unit tests covering the various positive and negative outcomes of each method. It would be best if you also had high-level tests that simulate business input. For these, you should have examples taken from real-world scenarios.

Try to have complete scenarios with all of the various anticipated inputs. These scenarios, in turn, should result in a detailed expected output. If you’re simulating a shopping cart in an e-commerce application, include several items of different types in your tests and ensure that all of the totals, tax, and shipping compute as expected.

One reason we do this comes from QA teams. Running through realistic scenarios is the kind of thing they would do by hand, as a smoke test. There’s no reason for something this simple to be a manual test, though. Ultimately it would be most helpful to replace all of the manual tests people like to do in your application with automated tests that use the realistic data that humans might enter.

And of course, you should also include negative tests as part of this. Include common mistakes that a human might enter to ensure that all of the validation is working and delivering error messages as expected.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: