### Platform-Specific Setup Directives Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Shows how to define setup commands that run on specific platforms. ```bash setup.posix=./setup.sh setup.windows=setup.bat ``` -------------------------------- ### Specify Setup Steps for Windows Systems Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Define setup commands, such as code generation or compilation, for Windows systems. ```properties setup.windows=generate_mocks.bat ``` -------------------------------- ### Specify Setup Steps for POSIX Systems Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Define setup commands, such as code generation or compilation, for POSIX-compliant systems. ```properties setup.posix=./generate_mocks.sh ``` -------------------------------- ### Phase 2: Flutter Installation Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-build-script.md Checks for and installs Flutter if not found in the PATH. Requires Git and network access. ```bash if ! command -v flutter then pushd .. git clone https://github.com/flutter/flutter.git export PATH="$PWD/flutter/bin:$PATH" popd fi ``` -------------------------------- ### Setup and Run DevTools Tests on Linux Source: https://github.com/flutter/tests/blob/main/_autodocs/test-registry-files.md Perform setup for DevTools customer tests on Linux, redirecting output to a file. This is followed by executing the test script. ```bash ./tool/flutter_customer_tests/setup.sh >> output.txt test.linux=./tool/flutter_customer_tests/test.sh ``` -------------------------------- ### Linux-Only Setup Command Source: https://github.com/flutter/tests/blob/main/_autodocs/configuration.md Execute a setup command exclusively on Linux using 'setup.linux='. This is useful for Linux-specific build or configuration tasks, with output optionally redirected. ```plaintext setup.linux=./tool/flutter_customer_tests/setup.sh >> output.txt ``` -------------------------------- ### Platform-Specific Setup Commands Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/test-registry-format.md Define shell commands for setup operations that are executed before 'update' and 'test' steps. Supports platform-specific variants for Windows, macOS, and Linux. ```plaintext setup.posix=setup.sh setup.windows=setup.bat ``` -------------------------------- ### Fetch Directives Example Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Demonstrates how to use fetch directives to clone a repository and checkout a specific commit. ```bash fetch=git clone https://github.com/USERNAME/REPOSITORY.git tests # Creates tests/ directory with repository contents fetch=git -C tests checkout 0123456789abcdef # Checks out specific commit hash ``` -------------------------------- ### Execute Single Setup Command Source: https://github.com/flutter/tests/blob/main/_autodocs/configuration.md Use the 'setup=' directive to specify a command that will be executed before the 'update' and 'test' phases. This command runs on all platforms. ```plaintext setup=./generate_mocks.sh ``` -------------------------------- ### Phase 3: Project Setup Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-build-script.md Sets up the Flutter project and adds the vm_service package dependency. Creates necessary project files if they don't exist. ```bash flutter create . flutter pub add vm_service ``` -------------------------------- ### CupertinoDialogTest Usage Examples Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-test-widgets.md Demonstrates how to instantiate the CupertinoDialogTest widget to control dialog visibility. Use these examples to test different dialog states. ```dart const CupertinoDialogTest() // Dialog visible const CupertinoDialogTest(visible: true) // Dialog visible const CupertinoDialogTest(visible: false) // Dialog hidden, logo only ``` -------------------------------- ### Get Help for Test Verification Script Source: https://github.com/flutter/tests/blob/main/README.md Display available options and usage instructions for the test verification script. ```bash ./scripts/verify_tests_on_main.sh --help ``` -------------------------------- ### Example Usage of StoryBoard Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-utilities.md Demonstrates how to use the StoryBoard widget with a list of ExpandingExpansionPanel widgets, specifying different scale values. ```dart const StoryBoard(widgets: [ ExpandingExpansionPanel(scale: 0.0), ExpandingExpansionPanel(scale: 0.05), ExpandingExpansionPanel(scale: 0.1), ExpandingExpansionPanel(scale: 0.2), ExpandingExpansionPanel(scale: 0.3), ExpandingExpansionPanel(scale: 0.4), ExpandingExpansionPanel(scale: 0.5), ExpandingExpansionPanel(scale: 0.8), ExpandingExpansionPanel(scale: 1.0), ]) ``` -------------------------------- ### Example Test File Structure Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Illustrates a typical project structure for organizing test files within a Flutter repository. ```yaml your_repo/ ├── test/ │ ├── widget_test.dart │ ├── integration_test.dart │ └── example_test.dart ├── lib/ │ └── ... (your source code) └── pubspec.yaml ``` -------------------------------- ### Run Application with TestScreen Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-main.md Example of how to run the application using the TestScreen widget, passing a list of widgets to be rendered and captured. ```dart runApp(TestScreen(widgets: [ Slate(title: title), const PageFlipTest(angle: 0.0), const CupertinoDialogTest(), ])); ``` -------------------------------- ### Example Usage of Slate Widget Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-utilities.md Demonstrates how to construct the title string with generation metadata and use it to instantiate the Slate widget. ```dart String get title => 'SKP COLLECTION\n' 'GENERATED ${DateTime.now()}\n' 'ON ${Platform.localHostname}\n' '${Platform.operatingSystem} ${Platform.operatingSystemVersion}'; Slate(title: title) ``` -------------------------------- ### Run Test Configuration Locally Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Execute your test definition against your local Flutter installation to verify its configuration. ```bash ./scripts/verify_tests_on_main.sh --local-flutter registry/your_project_name.test ``` -------------------------------- ### Example of _describe Usage Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-main.md Demonstrates the usage of the _describe function to format durations and indicate performance thresholds. Shows output for different duration values. ```dart _describe(Duration(milliseconds: 5)) // "5ms" _describe(Duration(milliseconds: 12)) // "12ms!" _describe(Duration(milliseconds: 150)) // "150ms!!" ``` -------------------------------- ### Slate Widget Usage Example Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-main.md Demonstrates how to instantiate the Slate widget with a formatted title string containing SKP generation metadata. ```dart Slate(title: 'SKP COLLECTION GENERATED 2024-06-28 12:34:56 ON my-computer Linux 6.17.0-1017-aws') ``` -------------------------------- ### CI Sharding Example Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md In a CI environment with 4 parallel jobs, assign a unique --shard-index to each job to ensure tests are distributed correctly. ```bash Job 1: --shards 4 --shard-index 0 Job 2: --shards 4 --shard-index 1 Job 3: --shards 4 --shard-index 2 Job 4: --shards 4 --shard-index 3 ``` -------------------------------- ### Main Application Entry Point Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-main.md Initializes the SKP generator application, sets up error handling, connects to the Flutter VM service, and starts the test widget rendering loop. This function is typically invoked automatically via build.sh. ```dart void main() async { // App initialization and test execution } ``` -------------------------------- ### setState Callback Example Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md An example of using a void callback within the setState method to update widget state. ```dart setState(() { _name = null; _captured = false; }); ``` -------------------------------- ### StatelessWidget Example Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md A basic StatelessWidget implementation. Widgets of this type do not maintain mutable state and are rebuilt when their parent rebuilds. ```dart class PageFlipTest extends StatelessWidget { @override Widget build(BuildContext context) => Transform(...); } ``` -------------------------------- ### StatefulWidget Example Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md A basic StatefulWidget implementation. Widgets of this type manage mutable state and require a corresponding State object. ```dart class TestScreen extends StatefulWidget { @override State createState() => _TestScreenState(); } ``` -------------------------------- ### ExpandingPhysicalModel Usage Examples Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-test-widgets.md Demonstrates how to instantiate the ExpandingPhysicalModel widget with different scale values. Use this widget to test Skia's native shadow rendering. ```dart const ExpandingPhysicalModel(scale: 0.0) const ExpandingPhysicalModel(scale: 0.5) const ExpandingPhysicalModel(scale: 1.0) ``` -------------------------------- ### ExpandingExpansionPanel Usage Examples Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-test-widgets.md Demonstrates how to use the ExpandingExpansionPanel widget with different scale values to represent collapsed, partially expanded, and fully expanded states. ```dart const ExpandingExpansionPanel(scale: 0.0) // Collapsed const ExpandingExpansionPanel(scale: 0.5) // Half expanded const ExpandingExpansionPanel(scale: 1.0) // Fully expanded ``` -------------------------------- ### StoryBoard Widget Usage Example Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-main.md Shows how to use the StoryBoard widget to render multiple ExpandingExpansionPanel widgets in a grid layout. The grid dimensions are calculated based on the number of widgets. ```dart StoryBoard(widgets: [ ExpandingExpansionPanel(scale: 0.0), ExpandingExpansionPanel(scale: 0.5), ExpandingExpansionPanel(scale: 1.0), ]) // Renders 3 widgets in a 2x2 grid with one placeholder ``` -------------------------------- ### Complex Test Configuration with Platform Directives Source: https://github.com/flutter/tests/blob/main/_autodocs/configuration.md An advanced .test file configuration that includes multiple contacts and platform-specific directives for setup and testing. This allows for tailored test execution on Linux, macOS, and Windows. ```bash contact=author@example.com contact=maintainer@example.com fetch=git -c core.longPaths=true clone https://github.com/flutter/devtools.git tests fetch=git -c core.longPaths=true -C tests checkout adce730d2817b70849d76d0257996a8cb273dd5d setup.linux=./tool/flutter_customer_tests/setup.sh >> output.txt update=packages/devtools_app update=packages/devtools_app_shared update=packages/devtools_extensions test.linux=./tool/flutter_customer_tests/test.sh test.macos=flutter test test.windows=flutter test ``` -------------------------------- ### ExpandingBlurs Usage Examples Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-test-widgets.md Shows how to use the ExpandingBlurs widget with various scale factors. This widget is useful for regression testing blur filter performance and correctness. ```dart const ExpandingBlurs(scale: 0.0) const ExpandingBlurs(scale: 0.5) const ExpandingBlurs(scale: 1.0) ``` -------------------------------- ### PageFlipTest Widget Usage Examples Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-test-widgets.md Demonstrates how to instantiate the `PageFlipTest` widget with different 'angle' values to achieve various rotation effects, from a flat view to a nearly edge-on perspective. ```dart const PageFlipTest(angle: 0.0) // Flat view const PageFlipTest(angle: 0.097) // Mid-rotation const PageFlipTest(angle: 0.194) // Nearly edge-on ``` -------------------------------- ### Run tests multiple times to detect flakiness Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/verify-tests-script.md Repeat test execution a specified number of times to identify flaky tests. This example runs tests 5 times. ```bash ./scripts/verify_tests_on_main.sh --local-flutter --repeat 5 ``` -------------------------------- ### Set Environment Variables for Windows Tests Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Set environment variables before running tests on Windows. This example sets `FLUTTER_TEST` to 1. ```properties test.windows=set FLUTTER_TEST=1 test.windows=flutter test ``` -------------------------------- ### State Object with Lifecycle Methods Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md An example of a State object for a StatefulWidget, including initState and dispose methods. It also demonstrates adding and removing a FrameTiming callback. ```dart class _TestScreenState extends State with TickerProviderStateMixin { @override void initState() { super.initState(); SchedulerBinding.instance!.addTimingsCallback(_framesRendered); } @override void dispose() { SchedulerBinding.instance!.removeTimingsCallback(_framesRendered); super.dispose(); } } ``` -------------------------------- ### Run tests in parallel across multiple shards Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/verify-tests-script.md Distribute test execution across a specified number of shards for parallel processing in CI environments. This example runs shard 0 out of 4 total shards. ```bash ./scripts/verify_tests_on_main.sh --shards 4 --shard-index 0 ``` -------------------------------- ### Reproduce Failing Test Locally Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Run a specific failing test locally using the local Flutter installation for faster iteration. This helps in debugging by allowing quick re-runs. ```bash ./scripts/verify_tests_on_main.sh --local-flutter registry/failing.test ``` -------------------------------- ### BoxDecoration Usage Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md Example of creating a BoxDecoration to style a widget's background, border, and shape. ```dart BoxDecoration( color: const Color(0xFF006666), border: Border.all(color: const Color(0xFF0000FF), width: 8.0), ) ``` -------------------------------- ### Typical Test Execution Sequence Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Demonstrates a typical sequence for running static analysis and unit/widget tests. ```bash test=flutter analyze --no-fatal-infos test=flutter test ``` -------------------------------- ### Phase 4: Build Preparation Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-build-script.md Removes old build artifacts, creates a new output directory, fetches dependencies, and applies Dart fixes. ```bash rm -rf test skps mkdir skps flutter packages get dart fix --apply ``` -------------------------------- ### Dart int Type Usage Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md Provides examples of integer variable declarations in Dart. Imported from dart:core. ```dart int _index = 0; int _subindex = 0; int itemCount = 5; ``` -------------------------------- ### Phase 5: Analysis and Build Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-build-script.md Performs static analysis and compiles the app into a bundle. Fails if analysis errors are detected. ```bash flutter analyze flutter build bundle ``` -------------------------------- ### Dart bool Type Usage Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md Shows examples of boolean variable declarations and assignments in Dart. Imported from dart:core. ```dart bool _captured = false; bool visible = true; final bool mounted = this.mounted; ``` -------------------------------- ### Create Test Definition File Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Copy the template file to create your project's test definition file. This file configures how your tests are fetched and run. ```bash cp registry/template.test registry/your_project_name.test ``` -------------------------------- ### Dart String Type Usage Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md Shows examples of string variable declarations and string interpolation in Dart. Imported from dart:core. ```dart String title = 'SKP COLLECTION...'; String filename = 'skps/flutter_$_name.skp'; ``` -------------------------------- ### Phase 1: Cleanup and Initialization Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-build-script.md Runs initial cleanup and registers a cleanup trap for exit. Use this to ensure artifacts are deleted on normal or error exit. ```bash cleanup if [ "$1" != "--no-clean" ] then trap cleanup EXIT fi ``` -------------------------------- ### Typical Update Sequence for Packages Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Illustrates the sequence for updating dependencies and applying code fixes in different packages within the tests directory. ```bash update=. # Root package update=packages/devtools_app # Sub-package 1 update=packages/devtools_shared # Sub-package 2 ``` -------------------------------- ### Fetch Test Suite with Git Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/test-registry-format.md Define shell commands to fetch the test suite using Git. Requires at least two lines: one for cloning and one for checking out a specific revision. Commands must be cross-platform and fetch tests into a directory named 'tests'. ```plaintext fetch=git clone https://github.com/USERNAME/REPOSITORY.git tests fetch=git -C tests checkout 0123456789abcdef0123456789abcdef01234567 ``` -------------------------------- ### Set Environment Variables for POSIX Tests Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Set environment variables before running tests on POSIX systems. This example sets `FLUTTER_TEST` to 1. ```properties test.posix=FLUTTER_TEST=1 flutter test ``` -------------------------------- ### Generate SKPs with build.sh Source: https://github.com/flutter/tests/blob/main/_autodocs/INDEX.md Generate SKPs for widgets or develop widgets without cleaning the build. ```bash ./skp_generator/build.sh [--no-clean] ``` ```bash ./skp_generator/build.sh ``` ```bash ./skp_generator/build.sh --no-clean ``` -------------------------------- ### Basic Test Definition Configuration Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Edit the test definition file to specify contact information, how to fetch your repository, and the commands to run your tests. ```properties contact=your_email@example.com contact=maintainer_email@example.com fetch=git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git tests fetch=git -C tests checkout COMMIT_SHA_HERE update=. test=flutter analyze --no-fatal-infos test=flutter test ``` -------------------------------- ### Initialize Git Submodules Source: https://github.com/flutter/tests/blob/main/_autodocs/configuration.md After cloning and checking out a specific commit, use 'git -C tests submodule update --init' to initialize any submodules within the repository. ```plaintext fetch=git -C tests submodule update --init ``` -------------------------------- ### Run Flutter Customer Tests Locally Source: https://github.com/flutter/tests/blob/main/README.md Execute all registered customer tests using the Flutter command in your PATH. Use the --help flag for additional options. ```bash ./scripts/verify_tests_on_main.sh --local-flutter ``` -------------------------------- ### Build SKP Files Source: https://github.com/flutter/tests/blob/main/_autodocs/INDEX.md Run the build script for the SKP generator application. This is used to capture test scenes as SKP files for performance testing purposes. ```bash ./skp_generator/build.sh ``` -------------------------------- ### Writing SKP Data to a File Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md Demonstrates how to create a File object and write byte data, such as decoded SKP data, to it. ```dart final File file = File(filename); await file.writeAsBytes(base64Decode(skpData)); ``` -------------------------------- ### Get VM Service Protocol Information Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md Retrieves information about the VM service connection endpoint. It's crucial to check if the server URI is available before attempting to connect. ```dart final developer.ServiceProtocolInfo info = await developer.Service.getInfo(); if (info.serverUri == null) { print('VM service unavailable'); exit(1); } ``` -------------------------------- ### TestConfiguration Pseudocode Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md A pseudocode representation of the TestConfiguration class used for parsing .test files, including contacts, fetch commands, setup commands, update paths, and test commands. ```dart class TestConfiguration { List contacts; List fetchCommands; List setupCommands; List updatePaths; List testCommands; } ``` -------------------------------- ### Configure Test Repetition Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Use the verify_tests_on_main.sh script with the --repeat flag to run tests multiple times for flakiness detection. ```bash ./scripts/verify_tests_on_main.sh \ --local-flutter \ --repeat 15 ``` -------------------------------- ### Fetch Test Code with Git Clone Source: https://github.com/flutter/tests/blob/main/_autodocs/configuration.md Use 'git clone' to fetch test code into the 'tests' directory. Ensure the command is cross-platform compatible and clones a specific commit, not the branch HEAD. ```plaintext fetch=git clone https://github.com/flutter/flutter.git tests ``` -------------------------------- ### Run multiple specific test files Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/verify-tests-script.md Execute a predefined list of test files using the local Flutter SDK. Provide paths to each `.test` file as separate arguments. ```bash ./scripts/verify_tests_on_main.sh --local-flutter registry/provider.test registry/flutter_packages.test ``` -------------------------------- ### Enable Verbose Output Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Use `set -x` to print commands as they execute for debugging purposes. This is useful for understanding the script's flow. ```bash ./scripts/verify_tests_on_main.sh --local-flutter --help ``` -------------------------------- ### Call VM Service Extension to Capture SKP Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-main.md Call the _flutter.screenshotSkp VM service extension to obtain base64-encoded SKP data. This is the initial step to generate SKP files. ```dart final Response response = await vmService.callServiceExtension('_flutter.screenshotSkp'); final String skp = response.json!['skp'] as String; // base64-encoded SKP data ``` -------------------------------- ### Dart Fix Code Migration Example Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Illustrates how `dart fix --apply` can automatically migrate deprecated API calls to their current equivalents. This is part of the update phase in the test execution model. ```dart // dart fix can automatically migrate code like: oldApiCall() // deprecated // to: newApiCall() // current API ``` -------------------------------- ### Develop SKP Widgets Source: https://github.com/flutter/tests/blob/main/_autodocs/00_START_HERE.md Builds SKP widgets without cleaning the build directory. Use this during development to speed up iteration. ```bash ./skp_generator/build.sh --no-clean ``` -------------------------------- ### Specify Package Update Paths Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/test-registry-format.md Define relative directory paths within the cloned 'tests' directory where Flutter package updates are applied. Each path must contain a 'pubspec.yaml' file. Commands 'flutter packages get' and 'dart fix --apply' are run automatically. ```plaintext update=. update=packages/devtools_app update=packages/devtools_shared ``` -------------------------------- ### Analyze and Test Provider Package Source: https://github.com/flutter/tests/blob/main/_autodocs/test-registry-files.md Perform static analysis and run tests for the Provider package, specifically targeting null-safe code. This is a popular state management library. ```bash flutter analyze --no-fatal-infos lib test/null_safe flutter test test/null_safe ``` -------------------------------- ### Phase 9: Validation Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-build-script.md Verifies the existence and non-zero size of the first expected SKP output file. Exits with an error if the file is missing. ```bash [ -s skps/flutter_Slate.01.skp ] || (echo 'ERROR! Output is missing expected files!' && exit 1) ``` -------------------------------- ### Run Standard Flutter Tests Source: https://github.com/flutter/tests/blob/main/_autodocs/test-registry-files.md Execute standard analysis and test commands for a Flutter project. Ensure the project is cloned and dependencies are managed. ```bash flutter analyze --no-fatal-infos flutter test ``` -------------------------------- ### Specify Update Paths for Multi-Package Projects Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md For multi-package projects, list each directory containing a `pubspec.yaml` file. ```properties update=packages/core update=packages/ui update=packages/utils ``` -------------------------------- ### Run a specific test file locally Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/verify-tests-script.md Execute a single test file using the local Flutter SDK. Specify the path to the `.test` file as an argument. ```bash ./scripts/verify_tests_on_main.sh --local-flutter registry/provider.test ``` -------------------------------- ### Configure Test Sharding Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Use the verify_tests_on_main.sh script with --shards and --shard-index to distribute tests across workers for parallel CI execution. ```bash ./scripts/verify_tests_on_main.sh \ --shards 4 \ --shard-index 0 ``` -------------------------------- ### Analyze and Test Flutter Projects Source: https://github.com/flutter/tests/blob/main/_autodocs/test-registry-files.md Commands to analyze project code for issues and run tests with specific configurations. ```bash flutter analyze --no-fatal-infos flutter test --dart-define=flutter_customer_test=true ``` -------------------------------- ### Phase 6: Platform Detection Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-build-script.md Detects the operating system and sets the PLATFORM variable accordingly (darwin-x64, linux-x64, or windows-x64). ```bash case "$(uname -s)" in Darwin) PLATFORM=darwin-x64 ;; Linux) PLATFORM=linux-x64 ;; MINGW*) PLATFORM=windows-x64 ;; esac ``` -------------------------------- ### Minimal Test Configuration Source: https://github.com/flutter/tests/blob/main/_autodocs/configuration.md A basic .test file configuration for running tests. It specifies contact information, fetches necessary code, updates packages, and defines test commands. ```bash contact=example@flutter.dev fetch=git clone https://github.com/flutter/packages.git tests fetch=git -C tests checkout 409793bcb784b9464def8698557005fb8851a9e6 update=packages/animations update=packages/rfw test=flutter analyze --no-fatal-infos test=flutter test ``` -------------------------------- ### StoryBoard Build Implementation Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-utilities.md The build method calculates grid dimensions and arranges widgets row-by-row, filling unused cells with placeholders. All cells expand equally to fill available space. ```dart @override Widget build(BuildContext context) { int dim = math.sqrt(widgets.length).ceil(); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ for (int y = 0; y < dim; y += 1) Expanded( child: Row( crossAxisAlignment: CrossAxisAlignment.stretch, textDirection: TextDirection.ltr, children: [ for (int x = 0; x < dim; x += 1) Expanded( child: y * dim + x < widgets.length ? widgets[y * dim + x] : const Placeholder(), ), ], ) ), ], ); } ``` -------------------------------- ### Capture SKP File via VM Service Extension Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-utilities.md The _capture function invokes a Flutter VM service extension to capture an SKP screenshot, decodes the base64 response, and writes it to a file. It also resets state for subsequent captures. ```dart Future _capture() async ``` ```dart final Response response = await vmService.callServiceExtension('_flutter.screenshotSkp'); ``` ```dart final String filename = 'skps/flutter_$_name.skp'; final String skpBase64 = response.json!['skp'] as String; ``` ```dart await File(filename).writeAsBytes(base64Decode(skpBase64)); ``` -------------------------------- ### Run Flutter Packages Tests on Windows and POSIX Source: https://github.com/flutter/tests/blob/main/_autodocs/test-registry-files.md Execute tests for Flutter packages, including setting an environment variable for consistent font rendering. Supports both Windows and POSIX environments. ```bash test.windows=set USE_FLUTTER_TEST_FONT=1 test.windows=.\customer_testing.bat test.posix=env USE_FLUTTER_TEST_FONT=1 ./customer_testing.sh ``` -------------------------------- ### Run all tests locally with local Flutter Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/verify-tests-script.md Use this command to execute all registered tests using a local Flutter SDK. This is useful for quick local verification. ```bash ./scripts/verify_tests_on_main.sh --local-flutter ``` -------------------------------- ### Phase 8: Headless Execution Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-build-script.md Executes the flutter_tester binary for headless app compilation and SKP generation. Configures packages, assets, and runs the compiled kernel. ```bash "$BIN_DIR/cache/artifacts/engine/$PLATFORM/flutter_tester" \ --run-forever \ --non-interactive \ --packages=.dart_tool/package_config.json \ --flutter-assets-dir=build/flutter_assets/ \ build/flutter_assets/kernel_blob.bin ``` -------------------------------- ### Analysis and Testing on Specific Directories Source: https://github.com/flutter/tests/blob/main/_autodocs/configuration.md Run Flutter analysis and tests on specified directories. Useful for targeted testing. ```bash test=flutter analyze --no-fatal-infos lib test/null_safe test=flutter test test/null_safe ``` -------------------------------- ### Run Flutter Tests Source: https://github.com/flutter/tests/blob/main/_autodocs/INDEX.md Execute tests locally, specify test files, repeat for flakiness, or use parallel execution. ```bash ./scripts/verify_tests_on_main.sh [options] [test-files...] ``` ```bash ./scripts/verify_tests_on_main.sh --local-flutter ``` ```bash ./scripts/verify_tests_on_main.sh --local-flutter registry/provider.test ``` ```bash ./scripts/verify_tests_on_main.sh --local-flutter --repeat 100 ``` ```bash ./scripts/verify_tests_on_main.sh --shards 4 --shard-index 0 ``` -------------------------------- ### Phase 7: Binary Location Resolution Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-build-script.md Resolves the absolute path to the Flutter bin directory, handling symlinks. ```bash FLUTTER="$(follow_links "$(type -P flutter)")" BIN_DIR="$(cd "${FLUTTER%/*}" ; pwd -P)" ``` -------------------------------- ### Specify Fetch Commands for Repository Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Use git commands to fetch a specific revision of your repository. Always pin a specific commit hash instead of fetching from branch HEAD. ```properties fetch=git clone https://github.com/YourOrg/your-repo.git tests fetch=git -C tests checkout 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d ``` -------------------------------- ### Specify Test Commands Using Shell Scripts Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Use platform-specific shell scripts for running tests, allowing for auto-selection based on the operating system. ```properties test.windows=scripts\run_tests.bat test.posix=scripts/run_tests.sh ``` -------------------------------- ### Execute Test Suite Commands Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/test-registry-format.md Define shell commands to execute the test suite. Supports platform-specific variants and requires commands to be runnable on Windows, macOS, or Linux. Multiple commands run sequentially, and any failure halts execution. ```plaintext test=flutter analyze --no-fatal-infos test=flutter test test=more_tests test=dart dev/extra_tests.dart test.windows=scripts\mytest.bat test.posix=scripts/mytest.sh ``` -------------------------------- ### Specify Platform-Specific Test Commands Source: https://github.com/flutter/tests/blob/main/_autodocs/contributing-tests.md Provide explicit test commands for Windows, macOS, and Linux to ensure cross-platform compatibility. ```properties test.windows=flutter test test.macos=flutter test test.linux=flutter test ``` -------------------------------- ### FrameTiming Information Source: https://github.com/flutter/tests/blob/main/_autodocs/types.md Logs the build and raster durations for each rendered frame. This callback is added using SchedulerBinding.instance.addTimingsCallback. ```dart void _framesRendered(List timings) { for (FrameTiming timing in timings) { print('build: ${timing.buildDuration}; raster: ${timing.rasterDuration}'); } } ``` -------------------------------- ### Slate Widget Build Implementation Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-utilities.md The build method for the Slate widget, which centers and displays the title text. ```dart @override Widget build(BuildContext context) { return Center(child: Text(title, textDirection: TextDirection.ltr)); } ``` -------------------------------- ### Slate Widget Source: https://github.com/flutter/tests/blob/main/_autodocs/api-reference/skp-generator-main.md A simple centered text widget displaying initialization information such as timestamp, platform, and OS version. It is used to show metadata during SKP generation. ```APIDOC ## Slate Widget ### Description A simple centered text widget displaying initialization information (timestamp, platform, OS version). ### Constructor `Slate({Key? key, required this.title})` ### Parameters #### Constructor Parameters - **title** (String) - Required - Text to display, typically contains SKP generation metadata. ### Example ```dart Slate(title: 'SKP COLLECTION\nGENERATED 2024-06-28 12:34:56\nON my-computer\nLinux 6.17.0-1017-aws') ``` ``` -------------------------------- ### Set Environment Variable on Windows Source: https://github.com/flutter/tests/blob/main/_autodocs/configuration.md Use the 'set' command to define an environment variable before running a command on Windows. ```bash test.windows=set VAR=value test.windows=command_using_VAR ``` -------------------------------- ### Manual Investigation of Test Failures Source: https://github.com/flutter/tests/blob/main/_autodocs/test-execution-model.md Preserve the `tests/` directory after a failure for manual investigation. This involves cloning the repository, setting up the environment, and running tests manually. ```bash # Modify the script or run phases manually git clone tests cd tests flutter packages get dart fix --apply flutter test # Inspect output and debug ``` -------------------------------- ### Fetch Test Code with Long Paths Option Source: https://github.com/flutter/tests/blob/main/_autodocs/configuration.md When dealing with deeply nested directories, use 'git -c core.longPaths=true clone' to fetch test code. This option helps prevent path length issues on certain file systems. ```plaintext fetch=git -c core.longPaths=true clone https://github.com/flutter/devtools.git tests ```