From 05f293d1b4e845cb0dfe7424b1076793e5f843f9 Mon Sep 17 00:00:00 2001 From: "k.mannweiler" <2012491@stud.hs-mannheim.de> Date: Mon, 6 Mar 2023 22:15:29 +0100 Subject: [PATCH] Added Tests --- test/unit_tests/date_service_test.dart | 3 +-- test/unit_tests/input_provider_test.dart | 5 +++++ test/unit_tests/settings_provider_test.dart | 2 +- test/unit_tests/workout_provider_test.dart | 17 +++++++++++------ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/test/unit_tests/date_service_test.dart b/test/unit_tests/date_service_test.dart index bdee660..afb3ee5 100644 --- a/test/unit_tests/date_service_test.dart +++ b/test/unit_tests/date_service_test.dart @@ -1,12 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:smoke_cess_app/mock/settings_mock.dart'; import 'package:smoke_cess_app/services/date_service.dart'; import 'package:smoke_cess_app/services/pages_service.dart'; -import 'package:smoke_cess_app/services/settings_service.dart'; import 'package:timezone/data/latest.dart' as tz; import 'package:timezone/timezone.dart'; +import '../mock/settings_mock.dart'; void main() async { tz.initializeTimeZones(); diff --git a/test/unit_tests/input_provider_test.dart b/test/unit_tests/input_provider_test.dart index 088b68b..36fcd3e 100644 --- a/test/unit_tests/input_provider_test.dart +++ b/test/unit_tests/input_provider_test.dart @@ -1,8 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:smoke_cess_app/providers/input_provider.dart'; +import 'package:smoke_cess_app/globals.dart' as globals; + +import '../mock/db_mock.dart'; void main() { + WidgetsFlutterBinding.ensureInitialized(); + globals.databaseService = DatabaseMock(); group('InputProvider', () { test('Initial values are correct', () { late final inputProvider = InputProvider(); diff --git a/test/unit_tests/settings_provider_test.dart b/test/unit_tests/settings_provider_test.dart index e8b8321..61e0c65 100644 --- a/test/unit_tests/settings_provider_test.dart +++ b/test/unit_tests/settings_provider_test.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:shared_preferences/shared_preferences.dart'; -import 'package:smoke_cess_app/mock/settings_mock.dart'; import 'package:smoke_cess_app/providers/settings_provider.dart'; +import '../mock/settings_mock.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); diff --git a/test/unit_tests/workout_provider_test.dart b/test/unit_tests/workout_provider_test.dart index 7c9cb40..45c7685 100644 --- a/test/unit_tests/workout_provider_test.dart +++ b/test/unit_tests/workout_provider_test.dart @@ -3,9 +3,12 @@ import 'package:flutter/material.dart'; import 'package:smoke_cess_app/providers/audio_provider.dart'; import 'package:smoke_cess_app/providers/timer_provider.dart'; import 'package:smoke_cess_app/providers/workout_provider.dart'; +import 'package:smoke_cess_app/globals.dart' as globals; +import '../mock/db_mock.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); + globals.databaseService = DatabaseMock(); group('WorkoutProvider', () { late WorkoutProvider workoutProvider; late TimerProvider timerProvider; @@ -65,12 +68,14 @@ void main() { expect(workoutProvider.isWorkoutComplete, false); }); - // test('save workout', () { - // workoutProvider.motivationBefore = 70; - // workoutProvider.motivationAfter = 80; - // workoutProvider.saveWorkout(); + test('save workout', () async { + workoutProvider.motivationBefore = 70; + workoutProvider.motivationAfter = 80; + workoutProvider.saveWorkout(); - // // -> hier in datenbank nachschauen obs geklappt hat - // }); + final result = await globals.databaseService.getWorkoutRecords(); + + expect(result.length, 1); + }); }); }