From 76693959fec4365ef226b251557e30f2028232fe Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 30 Mar 2026 09:48:18 +0200 Subject: [PATCH 1/3] Add support for skipping the build step in test command --- docs/cli-commands/test.mdx | 14 ++++++++++++++ packages/patrol_cli/README.md | 15 +++++++++++++++ packages/patrol_cli/lib/src/commands/test.dart | 9 ++++++++- .../patrol_cli/lib/src/runner/patrol_command.dart | 10 ++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/cli-commands/test.mdx b/docs/cli-commands/test.mdx index a043426190..d70ff9878e 100644 --- a/docs/cli-commands/test.mdx +++ b/docs/cli-commands/test.mdx @@ -140,6 +140,20 @@ patrol test --build-name=1.2.3 --build-number=123 patrol test --target integration_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. + ### Under the hood `patrol test` basically calls `patrol build` and then runs the built app diff --git a/packages/patrol_cli/README.md b/packages/patrol_cli/README.md index a5556a478a..38ba87017c 100644 --- a/packages/patrol_cli/README.md +++ b/packages/patrol_cli/README.md @@ -54,6 +54,21 @@ Read the documentation: - [setup](https://patrol.leancode.pl/getting-started) - [test command](https://patrol.leancode.co/cli-commands/test) +### 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. + [pub_badge]: https://img.shields.io/pub/v/patrol_cli.svg [pub_link]: https://pub.dartlang.org/packages/patrol_cli [pub_link_test]: https://pub.dartlang.org/packages/patrol diff --git a/packages/patrol_cli/lib/src/commands/test.dart b/packages/patrol_cli/lib/src/commands/test.dart index 77e11d1979..449ed5743d 100644 --- a/packages/patrol_cli/lib/src/commands/test.dart +++ b/packages/patrol_cli/lib/src/commands/test.dart @@ -63,6 +63,7 @@ class TestCommand extends PatrolCommand { usesBuildNumberOption(); usesUninstallOption(); + usesNoBuildOption(); usesAndroidOptions(); usesIOSOptions(); @@ -261,7 +262,13 @@ See https://github.com/leancodepl/patrol/issues/1316 to learn more. testServerPort: super.testServerPort, ); - await _build(androidOpts, iosOpts, macosOpts, device); + final noBuild = !boolArg('build'); + + if (noBuild) { + _logger.info('Skipping build step (--no-build)'); + } else { + await _build(androidOpts, iosOpts, macosOpts, 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 6d0094fe76..7d00cbc227 100644 --- a/packages/patrol_cli/lib/src/runner/patrol_command.dart +++ b/packages/patrol_cli/lib/src/runner/patrol_command.dart @@ -211,6 +211,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', From 1aa11badb144112012f451ce5f1602044a7fa6be Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 30 Mar 2026 14:56:00 +0200 Subject: [PATCH 2/3] Add -no-build option to patrol cli changelog --- packages/patrol_cli/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From 63b57a162a1ea3f1eaffd29ab18fdc37c1fb148d Mon Sep 17 00:00:00 2001 From: Lukas Date: Mon, 30 Mar 2026 16:11:54 +0200 Subject: [PATCH 3/3] Fix LateInitializationError for javaPath when using --no-build When --no-build skips the build step, loadJavaPathFromFlutterDoctor was never called, leaving the late field javaPath uninitialized. The execute method needs javaPath to set JAVA_HOME for Gradle. Now we call loadJavaPathFromFlutterDoctor on Android even when build is skipped. Co-Authored-By: Claude Opus 4.6 --- packages/patrol_cli/lib/src/commands/test.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/patrol_cli/lib/src/commands/test.dart b/packages/patrol_cli/lib/src/commands/test.dart index 6a60218130..dade867b63 100644 --- a/packages/patrol_cli/lib/src/commands/test.dart +++ b/packages/patrol_cli/lib/src/commands/test.dart @@ -322,6 +322,10 @@ See https://github.com/leancodepl/patrol/issues/1316 to learn more. 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);