Challenge: Unit Test Using Test After Development
Explore how to create unit tests after writing application code using NUnit framework. Learn to implement parameterized tests, setup methods, and test factorial, permutation, and combination calculations with exception handling. This lesson helps you understand balancing various testing approaches to improve test effectiveness.
We'll cover the following...
Introduction
In this project, you’ll write a unit test that tests the behavior of a class using the test after development approach. An assessment rubric is provided to give you an indication of whether the principles taught in this section have been applied.
Self-assessment rubric
| I have… | Emergent | Satisfactory | Excellent |
|---|---|---|---|
| Used parameterized tests | Did not use parameterized tests | Partially used parameterized tests | Used parameterized tests for test methods, wherever appropriate |
| Used a setup method | No setup method used | N/A | Setup method used |
| Pitched the tests at the right level | Inconsistent test approach—a combination of high-level and detailed approaches used | N/A | Consistent test approach—either a high-level or detailed approach adopted |
Quick dive into probability before unit testing
The challenge requires us to write code that calculates factorials, permutations, and combinations. Below is a brief description of each.
Factorial
The following is an outline of the factorial operation.
Calculation and example
is the product of all positive integers less than or equal to ,
For example:
Meaning of factorial
This operation is used in probability calculations where we want to find out the number of different ways to arrange ...