Skip to content

3.3 Architektur Mocktail #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: architektur
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
coverage:
dependency: transitive
description:
name: coverage
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -305,6 +312,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
mocktail:
dependency: "direct dev"
description:
name: mocktail
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
node_preamble:
dependency: transitive
description:
name: node_preamble
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -347,6 +368,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
shelf_static:
dependency: transitive
description:
name: shelf_static
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
shelf_web_socket:
dependency: transitive
description:
Expand All @@ -359,6 +394,20 @@ packages:
description: flutter
source: sdk
version: "0.0.99"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
source_maps:
dependency: transitive
description:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.10"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -401,13 +450,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
test:
dependency: transitive
description:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.21.4"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.12"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.16"
timing:
dependency: transitive
description:
Expand All @@ -429,6 +492,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "9.4.0"
watcher:
dependency: transitive
description:
Expand All @@ -443,6 +513,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
webkit_inspection_protocol:
dependency: transitive
description:
name: webkit_inspection_protocol
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
yaml:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dev_dependencies:

flutter_lints: ^2.0.0
build_runner: ^2.2.0
mocktail: ^0.3.0

flutter:
uses-material-design: true
Expand Down
28 changes: 24 additions & 4 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,37 @@

import 'package:counter_workshop/src/app.dart';
import 'package:counter_workshop/src/features/counter/data/datasources/local/counter.db.dart';
import 'package:counter_workshop/src/features/counter/data/datasources/remote/src/mock/counter_fake.api.dart';
import 'package:counter_workshop/src/features/counter/data/datasources/remote/counter.api.dart';
import 'package:counter_workshop/src/features/counter/data/datasources/remote/dtos/counter_response.dto.dart';
import 'package:counter_workshop/src/features/counter/data/repositories/counter.repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

class MockCounterApi extends Mock implements CounterApi {}

void main() {
// Mocktail solution
final mockCounterApi = MockCounterApi();
// fetch
when(() => mockCounterApi.fetchCounter(any())).thenAnswer(
(_) => Future.value(
CounterResponseDto(
counterValue: 0,
sysId: '1',
createdAt: DateTime.now(),
),
),
);
// update
when(() => mockCounterApi.updateCounter(any(), any())).thenAnswer(
(_) => Future.value(),
);

testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(
App(counterRepository: CounterRepository(counterApi: CounterFakeApi(), counterDatabase: CounterDatabase())),
const Duration(milliseconds: 300), // Because of FakeApi delay
App(counterRepository: CounterRepository(counterApi: mockCounterApi, counterDatabase: CounterDatabase())),
);

// Verify that our counter starts at 0.
Expand All @@ -26,7 +46,7 @@ void main() {

// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle(const Duration(milliseconds: 300)); // Because of FakeApi delay
await tester.pump(); // Because of FakeApi delay

// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
Expand Down