adding tests to the flutter results widget - lightly designing it. Added in a testing widget for being able to test widgets without a camera - camera components needs to be updated not to crash the app later though.
Also added real building and testing to the CICD
This commit is contained in:
+17
-16
@@ -14,34 +14,35 @@
|
|||||||
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
|
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
|
||||||
|
|
||||||
stages: # List of stages for jobs, and their order of execution
|
stages: # List of stages for jobs, and their order of execution
|
||||||
- build
|
- lint
|
||||||
- test
|
- test
|
||||||
|
- build
|
||||||
- deploy
|
- deploy
|
||||||
|
|
||||||
build-job: # This job runs in the build stage, which runs first.
|
before_script:
|
||||||
stage: build
|
- flutter pub get
|
||||||
|
- flutter clean
|
||||||
|
|
||||||
|
linting-code: # This job runs in the test stage.
|
||||||
|
stage: lint # It only starts when the job in the build stage completes successfully.
|
||||||
script:
|
script:
|
||||||
- echo "Compiling the code..."
|
- flutter analyze --no-fatal-infos --no-fatal-warnings
|
||||||
- echo "Compile complete."
|
|
||||||
tags:
|
tags:
|
||||||
- MacOS
|
- MacOS
|
||||||
|
|
||||||
unit-test-job: # This job runs in the test stage.
|
unit-tests: # This job runs in the test stage.
|
||||||
stage: test # It only starts when the job in the build stage completes successfully.
|
stage: test # It only starts when the job in the build stage completes successfully.
|
||||||
script:
|
script:
|
||||||
- echo "Running unit tests... This will take about 60 seconds."
|
- flutter test
|
||||||
- sleep 60
|
|
||||||
- echo "Code coverage is 90%"
|
|
||||||
tags:
|
tags:
|
||||||
- MacOS
|
- MacOS
|
||||||
|
|
||||||
|
build-debug:
|
||||||
lint-test-job: # This job also runs in the test stage.
|
stage: build
|
||||||
stage: test # It can run at the same time as unit-test-job (in parallel).
|
only:
|
||||||
|
- branches
|
||||||
script:
|
script:
|
||||||
- echo "Linting code... This will take about 10 seconds."
|
- flutter build appbundle --debug
|
||||||
- sleep 10
|
|
||||||
- echo "No lint issues found."
|
|
||||||
tags:
|
tags:
|
||||||
- MacOS
|
- MacOS
|
||||||
|
|
||||||
@@ -49,6 +50,6 @@ deploy-job: # This job runs in the deploy stage.
|
|||||||
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
|
stage: deploy # It only runs when *both* jobs in the test stage complete successfully.
|
||||||
script:
|
script:
|
||||||
- echo "Deploying application..."
|
- echo "Deploying application..."
|
||||||
- echo "Application successfully deployed."
|
- echo "Application successfully deployed. (JK gotta implement this sometime)"
|
||||||
tags:
|
tags:
|
||||||
- MacOS
|
- MacOS
|
||||||
@@ -3,11 +3,11 @@ import 'package:tensordex_mobile/widgets/poke_finder.dart';
|
|||||||
import '../tflite/model/outputs/recognition.dart';
|
import '../tflite/model/outputs/recognition.dart';
|
||||||
import '../tflite/model/outputs/stats.dart';
|
import '../tflite/model/outputs/stats.dart';
|
||||||
|
|
||||||
|
|
||||||
/// [PokeFinder] sends each frame for inference
|
/// [PokeFinder] sends each frame for inference
|
||||||
class Results extends StatefulWidget {
|
class Results extends StatefulWidget {
|
||||||
final List<Recognition> recognitions;
|
final List<Recognition> recognitions;
|
||||||
final Stats stats;
|
final Stats stats;
|
||||||
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
const Results(this.recognitions, this.stats, {Key? key}) : super(key: key);
|
const Results(this.recognitions, this.stats, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
@@ -23,6 +23,15 @@ class _ResultsState extends State<Results> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Text(widget.recognitions.toString());
|
return Column(
|
||||||
|
children: widget.recognitions
|
||||||
|
.map((recognition) => Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
|
children: [
|
||||||
|
Text(recognition.label.toString()),
|
||||||
|
Text(recognition.score.toString()),
|
||||||
|
],
|
||||||
|
)).toList(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-2
@@ -28,7 +28,21 @@ packages:
|
|||||||
name: camera
|
name: camera
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.9.7+1"
|
version: "0.9.8+1"
|
||||||
|
camera_android:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: camera_android
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.9.8+3"
|
||||||
|
camera_avfoundation:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: camera_avfoundation
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.9.8+2"
|
||||||
camera_platform_interface:
|
camera_platform_interface:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -211,7 +225,7 @@ packages:
|
|||||||
name: path_provider_android
|
name: path_provider_android
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.15"
|
version: "2.0.16"
|
||||||
path_provider_ios:
|
path_provider_ios:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
// This is a basic Flutter widget test.
|
|
||||||
//
|
|
||||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
|
||||||
// utility in the flutter_test package. For example, you can send tap and scroll
|
|
||||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
|
||||||
// tree, read text, and verify that the values of widget properties are correct.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
|
|
||||||
import 'package:tensordex_mobile/main.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
|
||||||
// Build our app and trigger a frame.
|
|
||||||
await tester.pumpWidget(const MyApp());
|
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
|
||||||
expect(find.text('0'), findsOneWidget);
|
|
||||||
expect(find.text('1'), findsNothing);
|
|
||||||
|
|
||||||
// Tap the '+' icon and trigger a frame.
|
|
||||||
await tester.tap(find.byIcon(Icons.add));
|
|
||||||
await tester.pump();
|
|
||||||
|
|
||||||
// Verify that our counter has incremented.
|
|
||||||
expect(find.text('0'), findsNothing);
|
|
||||||
expect(find.text('1'), findsOneWidget);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class WidgetTestApp extends StatelessWidget {
|
||||||
|
final List<Widget> widgets;
|
||||||
|
|
||||||
|
const WidgetTestApp(this.widgets, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(
|
||||||
|
title: 'Test App',
|
||||||
|
theme: ThemeData(
|
||||||
|
primarySwatch: Colors.lightBlue,
|
||||||
|
),
|
||||||
|
home: Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('TEST APP'),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: widgets,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
// This is a basic Flutter widget test.
|
||||||
|
//
|
||||||
|
// To perform an interaction with a widget in your test, use the WidgetTester
|
||||||
|
// utility in the flutter_test package. For example, you can send tap and scroll
|
||||||
|
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||||
|
// tree, read text, and verify that the values of widget properties are correct.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
import 'package:tensordex_mobile/tflite/model/outputs/recognition.dart';
|
||||||
|
import 'package:tensordex_mobile/tflite/model/outputs/stats.dart';
|
||||||
|
import 'package:tensordex_mobile/widgets/results.dart';
|
||||||
|
|
||||||
|
import '../widget_test_app.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||||
|
List<Recognition> recognitions = [
|
||||||
|
Recognition(1, 'Pikachu', 0.9),
|
||||||
|
Recognition(1, 'Raichu', 0.09),
|
||||||
|
Recognition(1, 'Pichu', 0.01),
|
||||||
|
];
|
||||||
|
|
||||||
|
Stats stat = Stats(
|
||||||
|
totalTime: 150,
|
||||||
|
preProcessingTime: 75,
|
||||||
|
inferenceTime: 50,
|
||||||
|
postProcessingTime: 25,
|
||||||
|
);
|
||||||
|
Results results = Results(recognitions, stat);
|
||||||
|
// Build our app and trigger a frame.
|
||||||
|
List<Widget> widgets = [results];
|
||||||
|
await tester.pumpWidget(WidgetTestApp(widgets));
|
||||||
|
|
||||||
|
// Verify that all of hte rcognitions can be found on the recognition widget
|
||||||
|
expect(find.text('Pikachu'), findsOneWidget);
|
||||||
|
expect(find.text('Raichu'), findsOneWidget);
|
||||||
|
expect(find.text('Pichu'), findsOneWidget);
|
||||||
|
expect(find.text('0.9'), findsOneWidget);
|
||||||
|
expect(find.text('0.09'), findsOneWidget);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user