Skip to content

Commit 253ea85

Browse files
DavidMina96HeshamMegid
authored andcommitted
Update mocking technique
1 parent a2e06dc commit 253ea85

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jobs:
77
- checkout
88
- run: flutter doctor
99
- run: flutter pub get
10+
- run: flutter pub run build_runner build --delete-conflicting-outputs
1011
- run: flutter test
1112
- run: flutter analyze .
1213
- run: flutter pub publish --dry-run

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Generated files
2+
*.mocks.dart
3+
14
# Miscellaneous
25
*.class
36
*.lock

pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ dependencies:
1515
instabug_flutter: '>=11.0.0 <12.0.0'
1616

1717
dev_dependencies:
18+
build_runner: ^2.0.3
1819
flutter_test:
1920
sdk: flutter
21+
mockito: 5.2.0
2022

2123
# For information on the generic Dart part of this file, see the
2224
# following page: https://dart.dev/tools/pub/pubspec

test/instabug_dio_interceptor_test.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import 'package:dio/dio.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:flutter/services.dart';
43
import 'package:flutter_test/flutter_test.dart';
54
import 'package:instabug_dio_interceptor/instabug_dio_interceptor.dart';
65
import 'package:instabug_flutter/instabug_flutter.dart';
6+
import 'package:instabug_flutter/src/generated/instabug.api.g.dart';
7+
import 'package:mockito/annotations.dart';
78

9+
import 'instabug_dio_interceptor_test.mocks.dart';
810
import 'mock_adapter.dart';
911

1012
class MyInterceptor extends InstabugDioInterceptor {
@@ -32,23 +34,24 @@ class MyInterceptor extends InstabugDioInterceptor {
3234
}
3335
}
3436

37+
@GenerateMocks(<Type>[
38+
InstabugHostApi,
39+
])
3540
void main() {
3641
TestWidgetsFlutterBinding.ensureInitialized();
3742
WidgetsFlutterBinding.ensureInitialized();
43+
44+
final MockInstabugHostApi mHost = MockInstabugHostApi();
45+
3846
late Dio dio;
3947
late MyInterceptor instabugDioInterceptor;
4048
const String appToken = '068ba9a8c3615035e163dc5f829c73be';
41-
setUpAll(() async {
42-
const MethodChannel('instabug_flutter')
43-
.setMockMethodCallHandler((MethodCall methodCall) async {
44-
switch (methodCall.method) {
45-
case 'getTags':
46-
return <String>['tag1', 'tag2'];
47-
default:
48-
return null;
49-
}
50-
});
49+
50+
setUpAll(() {
51+
Instabug.$setHostApi(mHost);
52+
NetworkLogger.$setHostApi(mHost);
5153
});
54+
5255
setUp(() {
5356
dio = Dio();
5457
dio.options.baseUrl = MockAdapter.mockBase;

0 commit comments

Comments
 (0)