Parameterised Tests Using unittest

Learn how to write parameterized tests using unittest.

In some cases, we'll notice that we need to run the same test case, but with different data. Instead of repeating, and generating duplicated tests, we can build a single one and exercise its condition with different values. This is called parameterized tests, and we'll start exploring these in this lesson.

Writing parameterized tests

Now, we would like to test how the threshold acceptance for the merge request works, just by providing data samples of what the context looks like without needing the entire MergeRequest object. We want to test the part of the status property that is after the line that checks whether it's closed, but independently.

Creating a new class

The best way to achieve this is to separate that component into another class, use composition, and then move on to test this new abstraction with its own test suite:

Get hands-on with 1400+ tech skills courses.