Search⌘ K

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.

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

n!n! is the product of all positive integers less than or equal to nn, n!=n×(n1)×(n2)×...×3×2×1n! = n{\times}(n-1){\times}(n-2){\times}...{\times}3{\times}2{\times}1

For example: 5!=5×4×3×2×1=1205! = 5{\times}4{\times}3{\times}2{\times}1 = 120

Meaning of factorial

This operation is used in probability calculations where we want to find out the number of different ways to arrange ...