September 2019
Beginner
512 pages
12h 52m
English
Now, let's suppose that we want to create a function that sums two numbers:
class Calculator { num sumTwoNumbers(num a, num b) { // TODO }}
We can write a unit test to evaluate this method implementation by using the test package:
import 'package:test/test.dart';import 'package:unit_tests/calculator.dart';void main() { Calculator calculator; setUp(() { calculator = Calculator(); }); test('calculator sumTwoNumbers() sum the both numbers', () { expect(calculator.sumTwoNumbers(1, 2), 3); });}
In the preceding example, we started by importing the test package main library that exposes functions, for example: setUp(), test(), and expect(). Each of the functions has specific roles, as follows:
Read now
Unlock full access