Clean Tests
Learn the basics of a clean test.
We'll cover the following
What a clean test looks like
After introducing what tests are and how to apply them to the test-driven development approach, let’s learn how to write clean tests.
The layout of a test
The arrange, act, and assert (AAA) paradigm is one of the most popular paradigms for structuring a good test.
- Arrange: Here, we set up everything to let the test run. That means we need to build, initialize, and prepare the object, which will be our system under test (SUT).
- Act: Here, we run the actual function of our SUT that we’re about to test.
- Assert: Here, we evaluate if what we get is what we expect. In other words, we assert the behavior of our SUT.
We can see an example of this in the following code snippet:
Get hands-on with 1200+ tech skills courses.