mirror of
https://github.com/flutter/samples.git
synced 2026-03-29 15:51:47 +00:00
Testing sample (#500)
This commit is contained in:
42
testing_app/test/models/favorites_test.dart
Normal file
42
testing_app/test/models/favorites_test.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2020 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:testing_app/models/favorites.dart';
|
||||
|
||||
void main() {
|
||||
group('Testing App Provider Tests', () {
|
||||
// Create an object of the provider.
|
||||
var favorites = Favorites();
|
||||
|
||||
test('A new item should be added', () {
|
||||
// Generate a random number.
|
||||
var number = Random().nextInt(50);
|
||||
|
||||
// Add the number to the list.
|
||||
favorites.add(number);
|
||||
|
||||
// Verify if the number was inserted.
|
||||
expect(favorites.items.contains(number), true);
|
||||
});
|
||||
|
||||
test('An item should be removed', () {
|
||||
// Generate a random number.
|
||||
var number = Random().nextInt(50);
|
||||
|
||||
// Add the number to the list.
|
||||
favorites.add(number);
|
||||
|
||||
// Verify if the number was inserted.
|
||||
expect(favorites.items.contains(number), true);
|
||||
|
||||
// Remove the number from the list.
|
||||
favorites.remove(number);
|
||||
|
||||
// Verify if the number was removed successfully.
|
||||
expect(favorites.items.contains(number), false);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user