Parameterised Tests Using unittest
Explore how to create parameterized tests in Python with the unittest framework. Understand techniques like using subTest for running tests with different data inputs, setting up test fixtures in setUp(), and structuring test classes to improve maintainability and debugging. Gain skills to write cleaner, reusable tests that efficiently verify multiple data conditions.
We'll cover the following...
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 ...