-
Notifications
You must be signed in to change notification settings - Fork 150
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 #1751 from leancodepl/lifecycle_callbacks_setupall
Add support for advanced test lifecycle callbacks - `setUpAll`
- Loading branch information
Showing
43 changed files
with
1,166 additions
and
179 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 |
---|---|---|
@@ -1,17 +1,53 @@ | ||
# Working on the test bundling feature | ||
|
||
_Test bundling_, also known as _native automation_, is a core feature of Patrol. | ||
It bridges the native world of tests on Android and iOS with the Flutter/Dart | ||
world of tests. | ||
|
||
It lives in the [patrol package](../packages/patrol). | ||
|
||
To learn more about test bundling, [read this article][test_bundling_article]. | ||
|
||
This document is a collection of tips and tricks to make it easier to work on | ||
test bundling-related code. | ||
|
||
### Tools | ||
|
||
`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). | ||
|
||
### Show Dart-side logs only | ||
|
||
Search for `flutter :`. | ||
|
||
### 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`. | ||
|
||
### I made some changes to test bundling code that result in a deadlock | ||
|
||
This can often happen when editing test bundling code. Because of various | ||
limitations of the `test` package, which Patrol has to base on, test bundling | ||
code is full of shared global mutable state and unobvious things happening in | ||
parallel. | ||
|
||
When trying to find the cause of a deadlock: | ||
|
||
- search for `await`s in custom functions provided by Patrol (e.g. | ||
`patrolTest()` and `patrolSetUpAll()`) and global lifecycle callbacks | ||
registered by the generated Dart test bundle or PatrolBinding (e.g. | ||
`tearDown()`s) | ||
- Use `print`s amply to pinpint where the code is stuck. | ||
|
||
In the future, we should think about how to refactor this code to be more | ||
maintainable and simpler. | ||
|
||
[test_bundling_article]: https://leancode.co/blog/patrol-2-0-improved-flutter-ui-testing |
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
32 changes: 30 additions & 2 deletions
32
packages/patrol/android/src/main/kotlin/pl/leancode/patrol/PatrolPlugin.kt
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,24 +1,52 @@ | ||
package pl.leancode.patrol | ||
|
||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
import io.flutter.embedding.engine.plugins.activity.ActivityAware | ||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler | ||
import io.flutter.plugin.common.MethodChannel.Result | ||
|
||
class PatrolPlugin : FlutterPlugin, MethodCallHandler { | ||
class PatrolPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { | ||
private lateinit var channel: MethodChannel | ||
|
||
private var isInitialRun: Boolean? = null | ||
|
||
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { | ||
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "pl.leancode.patrol/main") | ||
channel.setMethodCallHandler(this) | ||
} | ||
|
||
override fun onMethodCall(call: MethodCall, result: Result) { | ||
result.notImplemented() | ||
when (call.method) { | ||
"isInitialRun" -> result.success(isInitialRun) | ||
else -> result.notImplemented() | ||
} | ||
} | ||
|
||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | ||
channel.setMethodCallHandler(null) | ||
} | ||
|
||
override fun onAttachedToActivity(binding: ActivityPluginBinding) { | ||
val intent = binding.activity.intent | ||
if (!intent.hasExtra("isInitialRun")) { | ||
throw IllegalStateException("PatrolPlugin must be initialized with intent having isInitialRun boolean") | ||
} | ||
|
||
isInitialRun = intent.getBooleanExtra("isInitialRun", false) | ||
} | ||
|
||
override fun onDetachedFromActivityForConfigChanges() { | ||
// Do nothing | ||
} | ||
|
||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { | ||
// Do nothing | ||
} | ||
|
||
override fun onDetachedFromActivity() { | ||
// Do nothing | ||
} | ||
} |
Oops, something went wrong.