The motivation for writing unit tests shouldn't just be a simple way to test existing code, there are more benefits to consider:
- The fundamental idea behind unit tests is to write isolated testable code. To achieve this, it makes developers write smaller single-purpose methods and therefore avoid writing long spaghetti-like code.
- Refactoring existing code is easier because you can rewrite and test code in smaller portions. Refactored code should pass the same tests as the original code.
- Tests themselves can be considered as documentation and examples of expected behavior.
For this example, we'll write a console application that finds all numbers that are prime numbers, and all its digits are used only once. This is, for example, the number ...