Loading
Current section: Test Structure 6 exercises
lesson

Structure Your Tests

Transcript

00:00 So you have just written a simple automated test. What it does is executes the code, compares the result with the expectation, and throws an error if those don't match. In practice, any automated test consists of three phases. Those are setup, action, and assertion. Let's talk a bit more about them.

00:16 The setup phase is responsible for handling any side effects or dependencies that our code introduces. In our case, the greet function doesn't have any of those. It doesn't rely on other modules and doesn't do HTTP calls or anything like that. So we don't need to have an explicit setup phase to run it in the test. The action phase is responsible for putting our tested code in the right state.

00:36 In this scenario, it's calling the greet function with the right input and records the output, the greeting message. And then finally, the assertion phase does this comparison between the actual and expected results and throws an error. In this exercise, you will be working on rewriting this test to make it more declarative, isolated, and also readable.