Simplifying Tests with Common Setup Functions

Let’s learn about what testing techniques we can use in our Mastery project.

Testing Mastery

Recall that Mastery is the project that has and will comprise the majority of this course:

  • The project is a good illistration of tests, as it has an intricate structure with many moving parts.

  • Mastery quiz designers need to build complex structures.

  • Mastery end-users will answer questions with correct and incorrect answers, and the sequencing of questions will change based on those responses.

Writing tests is about establishing a flow. We prepare a question, ask the question, and compare the actual response with our expectations in each test. As the domain grows in complexity, preparing for a question will take more and more effort.

Structure of Mastery

For Mastery specifically, we perform the following actions:

  • Create quizzes with templates, as a teacher would.

  • Answer the questions those quizzes generate, as a user would.

  • Prove that users repeat sections until they achieve mastery by getting enough answers right.

Getting the setup right

We must get the setup right to get the rest of our tests right. Tests that pack too much into the test function itself obscure the test’s purpose, so we’ll put substantial effort into extracting common code from tests into setup.

We’re going to use two different types of setups—fictures and named setups.

Get hands-on with 1200+ tech skills courses.