Last active
September 19, 2023 14:20
-
-
Save bartekpacia/06b1712c2edb191aea6f1c93d44289ef to your computer and use it in GitHub Desktop.
Flutter Silesia #6 snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PatrolTester $; | |
$.native.grantPermissionWhenInUse() | |
$.native.grantPermissionOnlyThisTime(); | |
$.native.denyPermission(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.native.pressHome(); | |
$.native.openNotifications(); | |
$.native.tapOnNotificationBySelector( | |
Selector(textContains: 'Someone likes'), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
test('alpha', () {}); | |
test('bravo', () {}); | |
test('charlie', () {}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:test_api/src/backend/invoker.dart'; | |
void main() { | |
test('test_explorer', () { | |
final implicitTopLevelGroup = Invoker.current!.liveTest.groups.first; | |
_printGroupEntry(implicitTopLevelGroup); | |
}); | |
test('alpha', () {}); | |
test('bravo', () {}); | |
test('charlie', () {}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ dart test test/example_test.dart | |
Group: | |
Test: alpha | |
Test: bravo | |
Test: charlie | |
00:00 +4: All tests passed! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String requestedTest = "bravo"; // assume this gets passed in | |
void main() { | |
test('alpha', () {}); | |
test('bravo', () {}); | |
test('charlie', () {}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String requestedTest = "bravo"; // assume this gets passed in | |
void main() { | |
patrolTest('alpha', () {}); | |
patrolTest('bravo', () {}); | |
patrolTest('charlie', () {}); | |
} | |
void patrolTest(String testName, dynamic Function() body) { | |
test(testName, () async { | |
if (testName == requestedTest) { | |
await body(); | |
print('executed $testName'); | |
} else { | |
print('skipped $testName'); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ dart test test/example_test.dart | |
skipped alpha | |
executed bravo | |
skipped charlie | |
00:00 +3: All tests passed! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
WidgetsFlutterBinding.ensureInitialized(); | |
runApp(/* ... */); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | |
test('login flow', () { /* ... */ }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
PatrolBinding.ensureInitialized(); | |
patrolTest('login flow', ($) async { /* ... */ }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { | |
String? _currentTest; | |
Map<String, String> _testResults = {}; | |
PatrolBinding() { | |
setUp(() { | |
_currentTest = Invoker.current!.liveTest.parentGroupName; | |
}); | |
final oldReportTestException = reportTestException; | |
reportTestException = (details, testDescription) { | |
_testResults[_currentTest] = Failure(testDescription, '$details'); | |
oldReportTestException(details, testDescription); | |
}; | |
tearDown(() { | |
final result = _testResults[_currentTest]; | |
await patrolAppService.markDartTestAsCompleted(result); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { | |
String? _currentTest; | |
Map<String, String> _testResults = {}; | |
PatrolBinding() { | |
setUp(() { | |
_currentTest = Invoker.current!.liveTest.parentGroupName; | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { | |
String? _currentTest; | |
Map<String, String> _testResults = {}; | |
PatrolBinding() { | |
// remember current test | |
final oldReportTestException = reportTestException; | |
reportTestException = (details, testDescription) { | |
_testResults[_currentTest] = Failure(testDescription, '$details'); | |
oldReportTestException(details, testDescription); | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { | |
String? _currentTest; | |
Map<String, String> _testResults = {}; | |
PatrolBinding() { | |
// remember current test | |
// listen for failed tests | |
tearDown(() { | |
final result = _testResults[_currentTest]; | |
await patrolAppService.markDartTestAsCompleted(result); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { | |
String? _currentTest; | |
Map<String, String> _testResults = {}; | |
PatrolBinding() { | |
// remember current test | |
// listen for failed tests | |
// send results to instrumentation | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { | |
@override | |
Future<void> runTest( | |
Future<void> Function() testBody, | |
VoidCallback invariantTester, { | |
String description = '', | |
Duration? timeout, | |
}) async { | |
await super.runTest( | |
testBody, | |
invariantTester, | |
description: description, | |
); | |
_testResults[description] ??= _success; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment