Free preview.You're sampling one lesson — enroll free to unlock all 8 lessons and track your progress.
Enroll free lesson
Why and What to Test
Why and What to Test
In this lesson — part of Testing Fundamentals — you'll learn why and what to test in Dart and why it matters in real work.
Why it matters
Tests prove your code works and keep it working as you change it.
Key ideas
- What to test
- Arrange-Act-Assert
- Running a test suite
- Good vs. brittle tests
In practice
Here's how it looks in idiomatic Dart:
import 'package:test/test.dart';
int add(int a, int b) => a + b;
void main() {
test('adds two numbers', () {
expect(add(2, 3), equals(5));
});
}
Dart note: The package:test framework is the Dart standard; you group cases with test(...) and assert with expect(actual, matcher).
Try it yourself
Exercise: In Dart, write three tests for a function that reverses a string.
Recap
You now understand why and what to test and can apply it in Dart. Mark this lesson complete and continue to the next one.
