Testing in Flutter

Sep 19 2023 · Dart 2.19.3, Flutter 3.7.6, Android Studio 2021.3.1, Visual Studio Code 1.7.4

Part 2: Write Unit Tests

04. Your First Unit Test

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 03. What Are You Going to Test? Next episode: 05. Test Change Notifier

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Now that you know what you will test, let us start with writing our first unit test. Head over to the test folder and create a new file called quotes_api_test. You will be writing your first unit test in this file, and as the name suggests, you will be testing the quotes API. But before we start testing the API, let us first write a simple test to see how the test works.

void main() {

}
import 'package:flutter_test/flutter_test.dart';
void main() {
  test('Simple Test', () {
    expect(1, 1);
  });
}
flutter test test/quotes_api_test.dart
void main() {
  test('Simple Test', () {
    expect(1, 2);
  });
}
test('quotes json test', () {
  final quote = Quotes(1, '', '');

  expect(quote.id, 1);
  expect(quote.author, '');
  expect(quote.quote, '');
});