-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1721 from leancodepl/lifecycle_callbacks
Add support for basic test lifecycle callbacks
- Loading branch information
Showing
8 changed files
with
153 additions
and
37 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Working on the test bundling feature | ||
|
||
`adb logcat` is your friend. Spice it up with `-v color`. If you need something | ||
more powerful, check out [`purr`](https://github.com/google/purr). | ||
|
||
### Find out when a test starts | ||
|
||
Search for `TestRunner: started`. | ||
|
||
``` | ||
09-21 12:24:09.223 23387 23406 I TestRunner: started: runDartTest[callbacks_test testA](pl.leancode.patrol.example.MainActivityTest) | ||
``` | ||
|
||
### Find out when a test ends | ||
|
||
Search for `TestRunner: finished`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 2.4.0-dev.3 | ||
|
||
- Add support for iOS 11 and 12 (#1733) | ||
|
||
## 2.3.1 | ||
|
||
- Add support for iOS 11 and 12 (#1733) | ||
|
57 changes: 57 additions & 0 deletions
57
packages/patrol/example/integration_test/callbacks_test.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:patrol/src/extensions.dart'; | ||
// ignore: depend_on_referenced_packages | ||
import 'package:test_api/src/backend/invoker.dart'; | ||
|
||
import 'common.dart'; | ||
|
||
String get currentTest => Invoker.current!.fullCurrentTestName(); | ||
|
||
void _print(String text) => print('PATROL_DEBUG: $text'); | ||
|
||
void main() { | ||
patrolSetUp(() async { | ||
await Future<void>.delayed(Duration(seconds: 1)); | ||
_print('setting up before $currentTest'); | ||
}); | ||
|
||
patrolTearDown(() async { | ||
await Future<void>.delayed(Duration(seconds: 1)); | ||
_print('tearing down after $currentTest'); | ||
}); | ||
|
||
patrolTest('testFirst', nativeAutomation: true, _body); | ||
|
||
group('groupA', () { | ||
patrolSetUp(() async { | ||
if (currentTest == 'callbacks_test groupA testB') { | ||
throw Exception('PATROL_DEBUG: Crashing testB on purpose!'); | ||
} | ||
_print('setting up before $currentTest'); | ||
}); | ||
|
||
patrolTearDown(() async { | ||
_print('tearing down after $currentTest'); | ||
}); | ||
|
||
patrolTest('testA', nativeAutomation: true, _body); | ||
patrolTest('testB', nativeAutomation: true, _body); | ||
patrolTest('testC', nativeAutomation: true, _body); | ||
}); | ||
|
||
patrolTest('testLast', nativeAutomation: true, _body); | ||
} | ||
|
||
Future<void> _body(PatrolTester $) async { | ||
final testName = Invoker.current!.fullCurrentTestName(); | ||
_print('test body: name=$testName'); | ||
|
||
await createApp($); | ||
|
||
await $(FloatingActionButton).tap(); | ||
expect($(#counterText).text, '1'); | ||
|
||
await $(#textField).enterText(testName); | ||
|
||
await $.pumpAndSettle(duration: Duration(seconds: 2)); | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'package:meta/meta.dart'; | ||
// ignore: implementation_imports | ||
import 'package:test_api/src/backend/invoker.dart'; | ||
|
||
/// Provides convenience methods for [Invoker]. | ||
@internal | ||
extension InvokerX on Invoker { | ||
/// Returns the full name of the current test (names of all ancestor groups + | ||
/// name of the current test). | ||
String fullCurrentTestName() { | ||
final parentGroupName = liveTest.groups.last.name; | ||
final testName = liveTest.individualName; | ||
|
||
return '$parentGroupName $testName'; | ||
} | ||
|
||
/// Returns the name of the current test only. No group prefixes. | ||
String get currentTestName => liveTest.individualName; | ||
} |
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
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