Skip to content

Commit 55f4d2c

Browse files
authored
Integration testing (#37)
* Refactor tests to allow for integration testing * Create github actions
1 parent 73b336a commit 55f4d2c

34 files changed

+331
-223
lines changed

.github/workflows/test.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: test
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
branches: [master]
7+
8+
env:
9+
PUB_ENVIRONMENT: bot.github
10+
11+
jobs:
12+
linux:
13+
name: webcrypto on Linux desktop / Chrome / Firefox
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: subosito/flutter-action@v2
18+
with:
19+
channel: 'stable'
20+
- name: Configure Flutter
21+
run: |
22+
sudo apt-get update -y
23+
sudo apt-get install -y ninja-build libgtk-3-dev
24+
flutter config --no-analytics
25+
flutter config --enable-linux-desktop
26+
- run: flutter pub get
27+
- run: flutter pub run webcrypto:setup
28+
- run: flutter test
29+
- run: flutter test --platform chrome
30+
- run: xvfb-run flutter test integration_test/webcrypto_test.dart -d linux
31+
working-directory: ./example
32+
- uses: nanasess/setup-chromedriver@v1
33+
- name: Run integration_test with chromedriver
34+
working-directory: ./example
35+
run: |
36+
xvfb-run ../tool/with-chromedriver.sh flutter drive \
37+
--driver=test_driver/integration_test.dart \
38+
--target=integration_test/webcrypto_test.dart \
39+
-d chrome
40+
- run: xvfb-run flutter pub run test -p vm,chrome,firefox
41+
macos:
42+
name: webcrypto on macOS Chrome / Firefox
43+
runs-on: macos-latest
44+
steps:
45+
- uses: actions/checkout@v3
46+
- uses: subosito/flutter-action@v2
47+
with:
48+
channel: 'stable'
49+
architecture: x64
50+
- name: Configure Flutter
51+
run: |
52+
flutter config --no-analytics
53+
flutter config --enable-macos-desktop
54+
- run: flutter pub get
55+
- run: flutter pub run webcrypto:setup
56+
- run: flutter test
57+
- run: flutter test --platform chrome
58+
# TODO: Enable macos desktop when supported
59+
#- run: flutter test integration_test/webcrypto_test.dart -d macos
60+
# working-directory: ./example
61+
- uses: nanasess/setup-chromedriver@v1
62+
- name: Run integration_test with chromedriver
63+
working-directory: ./example
64+
run: |
65+
../tool/with-chromedriver.sh flutter drive \
66+
--driver=test_driver/integration_test.dart \
67+
--target=integration_test/webcrypto_test.dart \
68+
-d chrome
69+
- run: flutter pub run test -p vm,chrome,firefox
70+
ios:
71+
name: webcrypto on iOS emulator (iPhone)
72+
runs-on: macos-latest
73+
steps:
74+
- uses: actions/checkout@v3
75+
- uses: subosito/flutter-action@v2
76+
with:
77+
channel: 'stable'
78+
architecture: x64
79+
- name: Configure Flutter
80+
run: |
81+
flutter config --no-analytics
82+
- uses: futureware-tech/simulator-action@v1
83+
with:
84+
model: 'iPhone 12'
85+
- run: flutter pub get
86+
- run: flutter test integration_test/webcrypto_test.dart -d iphone
87+
working-directory: ./example
88+
android:
89+
name: webcrypto on Android emulator
90+
runs-on: macos-latest
91+
steps:
92+
- uses: actions/checkout@v3
93+
- uses: actions/setup-java@v2
94+
with:
95+
distribution: 'zulu'
96+
java-version: '11'
97+
- uses: subosito/flutter-action@v2
98+
with:
99+
channel: 'stable'
100+
architecture: x64
101+
- name: Configure Flutter
102+
run: |
103+
flutter config --no-analytics
104+
- run: flutter pub get
105+
- name: Run flutter test integration_test/webcrypto_test.dart -d android
106+
uses: reactivecircus/android-emulator-runner@v2
107+
with:
108+
api-level: 28
109+
working-directory: ./example
110+
script: flutter test integration_test/webcrypto_test.dart -d android
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:integration_test/integration_test.dart';
4+
5+
import 'package:webcrypto_example/main.dart' as app;
6+
import 'package:webcrypto/src/testing/testing.dart';
7+
8+
void main() {
9+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
10+
11+
group('package:webcrypto tests', () {
12+
runAllTests(test);
13+
});
14+
15+
group('webcrypto_example test', () {
16+
testWidgets('app can compute a hash', (tester) async {
17+
app.main();
18+
await tester.pumpAndSettle();
19+
20+
expect(find.textContaining('2aae6c35c94'), findsNothing);
21+
22+
final input = find.byType(TextField);
23+
await tester.enterText(input, 'hello world');
24+
25+
final refresh = find.byTooltip('compute hash');
26+
await tester.tap(refresh);
27+
28+
await tester.pumpAndSettle();
29+
30+
expect(find.textContaining('2aae6c35c94'), findsOneWidget);
31+
});
32+
});
33+
}

example/pubspec.lock

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ packages:
77
name: _fe_analyzer_shared
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "41.0.0"
10+
version: "46.0.0"
1111
analyzer:
1212
dependency: transitive
1313
description:
1414
name: analyzer
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "4.2.0"
17+
version: "4.6.0"
1818
archive:
1919
dependency: transitive
2020
description:
@@ -173,6 +173,11 @@ packages:
173173
url: "https://pub.dartlang.org"
174174
source: hosted
175175
version: "4.0.1"
176+
integration_test:
177+
dependency: "direct dev"
178+
description: flutter
179+
source: sdk
180+
version: "0.0.0"
176181
io:
177182
dependency: transitive
178183
description:
@@ -277,7 +282,7 @@ packages:
277282
name: shelf
278283
url: "https://pub.dartlang.org"
279284
source: hosted
280-
version: "1.3.1"
285+
version: "1.3.2"
281286
shelf_packages_handler:
282287
dependency: transitive
283288
description:

example/pubspec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ description: Demonstrates how to use the webcrypto plugin.
2020
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
2121

2222
environment:
23-
sdk: ">=2.17.0 <3.0.0"
24-
flutter: ">=3.0.0"
23+
sdk: '>=2.17.0 <3.0.0'
24+
flutter: '>=3.0.0'
2525

2626
dependencies:
2727
flutter:
@@ -40,6 +40,8 @@ dependencies:
4040
dev_dependencies:
4141
flutter_test:
4242
sdk: flutter
43+
integration_test:
44+
sdk: flutter
4345
flutter_driver:
4446
sdk: flutter
4547
test: ^1.5.2
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'package:integration_test/integration_test_driver.dart';
16+
17+
Future<void> main() => integrationDriver();

example/test_driver/webcrypto_tester.dart

Lines changed: 0 additions & 62 deletions
This file was deleted.

example/test_driver/webcrypto_tester_test.dart

Lines changed: 0 additions & 51 deletions
This file was deleted.

lib/src/testing/testing.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import 'utils/utils.dart';
16+
import 'utils/testrunner.dart' show TestRunner;
17+
18+
// TestRunner implementations
19+
import 'webcrypto/aescbc.dart' as aescbc;
20+
import 'webcrypto/aesctr.dart' as aesctr;
21+
import 'webcrypto/aesgcm.dart' as aesgcm;
22+
import 'webcrypto/ecdh.dart' as ecdh;
23+
import 'webcrypto/ecdsa.dart' as ecdsa;
24+
import 'webcrypto/hkdf.dart' as hkdf;
25+
import 'webcrypto/hmac.dart' as hmac;
26+
import 'webcrypto/pbkdf2.dart' as pbkdf2;
27+
import 'webcrypto/rsaoaep.dart' as rsaoaep;
28+
import 'webcrypto/rsapss.dart' as rsapss;
29+
import 'webcrypto/rsassapkcs1v15.dart' as rsassapkcs1v15;
30+
31+
// Other test files, that don't use TestRunner
32+
import 'webcrypto/random.dart' as random;
33+
import 'webcrypto/digest.dart' as digest;
34+
35+
/// Test runners from all test files except `digest.dart` and
36+
/// `random.dart`, which do not use [TestRunner].
37+
final _testRunners = <TestRunner>[
38+
aescbc.runner,
39+
aesctr.runner,
40+
aesgcm.runner,
41+
ecdh.runner,
42+
ecdsa.runner,
43+
hkdf.runner,
44+
hmac.runner,
45+
pbkdf2.runner,
46+
rsaoaep.runner,
47+
rsapss.runner,
48+
rsassapkcs1v15.runner,
49+
];
50+
51+
/// Utility function that runs all tests using [test].
52+
///
53+
/// This makes it easy to run tests from `flutter drive`, when testing on a
54+
/// device.
55+
void runAllTests(TestFn test) {
56+
for (final r in _testRunners) {
57+
r.runTests(test: test);
58+
}
59+
// We don't use [TestRunner] for all tests, so we just add them manually.
60+
random.runTests(test: test);
61+
digest.runTests(test: test);
62+
}
File renamed without changes.

0 commit comments

Comments
 (0)