diff --git a/docs/cli-commands/test.mdx b/docs/cli-commands/test.mdx index 63ecb1414c..43271014ca 100644 --- a/docs/cli-commands/test.mdx +++ b/docs/cli-commands/test.mdx @@ -143,6 +143,20 @@ patrol test --build-name=1.2.3 --build-number=123 patrol test --target patrol_test/login_test.dart --build-name=1.2.3 --build-number=123 ``` +### Skipping the build step + +If you have already built your app binaries using [`patrol build`][patrol_build], +you can skip the build step with `--no-build`: + +``` +patrol build android +patrol test --no-build +``` + +This is useful in CI pipelines or iterative workflows where you want to build +once and run tests multiple times without rebuilding. The previously built +binaries are picked up from their default output paths. + ### Isolation of test runs To achieve full isolation between test runs: diff --git a/packages/patrol_cli/CHANGELOG.md b/packages/patrol_cli/CHANGELOG.md index fcc2534a36..ceffaf7a0f 100644 --- a/packages/patrol_cli/CHANGELOG.md +++ b/packages/patrol_cli/CHANGELOG.md @@ -1,5 +1,6 @@ ## 4.3.1 +- Add `--no-build` flag to `patrol test` to skip the build step and use previously built binaries. - Update dependencies. ## 4.3.0 diff --git a/packages/patrol_cli/README.md b/packages/patrol_cli/README.md index 3f5631cc34..0da1a94f4d 100644 --- a/packages/patrol_cli/README.md +++ b/packages/patrol_cli/README.md @@ -75,7 +75,22 @@ Read the documentation: - [setup](https://patrol.leancode.pl/getting-started) - [test command](https://patrol.leancode.co/cli-commands/test) -## 🛠️ Maintained by LeanCode +### Skipping the build step + +If you want to separate the build and test steps (e.g. to build once and run +tests multiple times), you can use `patrol build` to pre-build and then +`patrol test --no-build` to run with the existing binaries: + +```console +$ patrol build android +$ patrol test --no-build +``` + +The `--no-build` flag tells `patrol test` to skip the build step entirely and +use the binaries previously produced by `patrol build android` (or +`patrol build ios`). The binaries are expected at their default output paths. + +## Maintained by LeanCode
@@ -103,7 +118,6 @@ We are **top-tier experts** focused on Flutter Enterprise solutions. [Check our other packages](https://pub.dev/packages?q=publisher%3Aleancode.co&sort=downloads)
- [pub_link]: https://pub.dartlang.org/packages/patrol_cli [pub_badge_style]: https://img.shields.io/badge/style-leancode__lint-black [pub_badge_link]: https://pub.dartlang.org/packages/leancode_lint diff --git a/packages/patrol_cli/lib/src/commands/test.dart b/packages/patrol_cli/lib/src/commands/test.dart index 58ecf093d2..dade867b63 100644 --- a/packages/patrol_cli/lib/src/commands/test.dart +++ b/packages/patrol_cli/lib/src/commands/test.dart @@ -66,6 +66,7 @@ class TestCommand extends PatrolCommand { usesBuildNumberOption(); usesUninstallOption(); + usesNoBuildOption(); usesAndroidOptions(); usesIOSOptions(); @@ -319,11 +320,16 @@ See https://github.com/leancodepl/patrol/issues/1316 to learn more. browserArgs: stringArg('web-browser-args'), ); - // No need to build web app for testing. It's done in the execute method. - if (device.targetPlatform != TargetPlatform.web) { + if (!boolArg('build')) { + _logger.info('Skipping build step (--no-build)'); + if (device.targetPlatform == TargetPlatform.android) { + await _androidTestBackend + .loadJavaPathFromFlutterDoctor(flutterOpts.command); + } + } else if (device.targetPlatform != TargetPlatform.web) { + // No need to build web app for testing. It's done in the execute method. await _build(androidOpts, iosOpts, macosOpts, webOpts, device); } - await _preExecute(androidOpts, iosOpts, macosOpts, device, uninstall); if (coverageEnabled) { diff --git a/packages/patrol_cli/lib/src/runner/patrol_command.dart b/packages/patrol_cli/lib/src/runner/patrol_command.dart index 460f698ae8..5fd2bc5275 100644 --- a/packages/patrol_cli/lib/src/runner/patrol_command.dart +++ b/packages/patrol_cli/lib/src/runner/patrol_command.dart @@ -241,6 +241,16 @@ abstract class PatrolCommand extends Command { ); } + void usesNoBuildOption() { + argParser.addFlag( + 'build', + defaultsTo: true, + help: + 'Build the app before running tests. ' + 'Use --no-build to skip the build step and use previously built binaries.', + ); + } + void usesBuildNameOption() { argParser.addOption( 'build-name',