Challenge: Unit test Quiz app #
Introduction #
This challenge is based on a modified version of the Quiz app from here.
In this version I’ve extract the logic from UI, such that unit tests can be written for the logic.
The logic have been extracted from QuizScreen
and moved to QuizModel
class
which extends
ChangeNotifier.
A ChangeNotifier
is an implementation of the classic observer
pattern.
Here is a short YouTube video I’ve found that shows how ChangeNotifier
can be
used.
Provider 📱 Simple State Management • Flutter Tutorial
Getting started #
Clone the separate-logic branch of quiz app repository.
git clone -b separate-logic https://github.com/fluttered-book/quiz.git
Run application
dart run
Run tests
dart test
What to do #
Write unit-tests for QuizModel
found in lib/quiz_model.dart
.
Your tests should be written in test/quiz_model_test.dart
.
QuizModel
has side effects.
In fact its methods are void.
- How can you write tests, so that a change in the logic will make a test fail?
- What would be a good description for each of the test you come up with?