O'Reilly logo

Dart Essentials by Martin Sikora

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unit testing

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required