This document describes how to run and write tests for the Zstandard plugin and CLI.
Platform-specific packages (Android, iOS, macOS, Web) use integration tests that run on real devices, emulators, or Chrome. This gives full coverage without skips.
- Android: Tests run in
zstandard_android/example/integration_test/on an Android emulator. - iOS: Tests run in
zstandard_ios/example/integration_test/on an iOS simulator. - macOS: Tests run in
zstandard_macos/example/integration_test/after the native framework is built. - Web: Unit tests run with
flutter test -d chrome(Chrome required; no VM execution).
Linux and Windows tests still run only on their native OS in CI.
- Android: Android SDK with emulator (API 28+). Set
ANDROID_HOMEorANDROID_SDK_ROOT. - iOS: Xcode with simulators installed.
- macOS: Xcode command-line tools.
- Web: Chrome browser.
See Emulator and simulator setup for details.
From the repository root:
./scripts/test_all_integration.shThis runs unit tests for pure Dart packages, then integration tests for Android (emulator), iOS (simulator), macOS (after building the framework), and Web (Chrome), without skipping platform-specific tests.
Android (starts emulator if needed; first boot can take 2–4 minutes):
./scripts/test_android_integration.shTo skip Android when running the full suite (e.g. if no emulator or slow machine): ZSTANDARD_SKIP_ANDROID=1 ./scripts/test_all_integration.sh. To allow more time for boot: ZSTANDARD_AVD_BOOT_TIMEOUT=300 ./scripts/test_android_integration.sh.
iOS (boots simulator if needed):
./scripts/test_ios_integration.shmacOS (Flutter builds the app when running tests):
cd zstandard_macos/example
flutter test integration_test/ -d macosWeb (Chrome):
./scripts/test_web_integration.shcd zstandard
flutter testcd zstandard_platform_interface
flutter test- Android, iOS, macOS: Platform tests live in each package’s
example/integration_test/. Use the scripts above (e.g../scripts/test_android_integration.sh). The packagetest/directory only contains a pointer test. - Linux, Windows: From the package directory,
flutter test(run on the corresponding OS). - Web: From
zstandard_web, runflutter test -d chrome(Chrome required).
cd zstandard_cli
dart test./scripts/test_all.shUse ./scripts/test_all_integration.sh for full coverage without skips (see above).
The main plugin’s example app also has integration tests:
cd zstandard/example
flutter test integration_test/Use -d <device_id> to run on a specific device or simulator.
- Unit tests: In each package’s
test/directory. Usetest()andgroup()frompackage:testorpackage:flutter_test. Mock the platform when testing the main plugin or platform interface. For Android, iOS, macOS, and Web, the main platform tests have been moved to integration tests. - Integration tests: In each platform example’s
integration_test/directory. They run on a real device, emulator, simulator, or Chrome and exercise the full native/WASM stack with no skips.
- Contract tests: Verify that the default implementation (method channel) throws
UnimplementedErrorforcompressanddecompressif not overridden. VerifygetPlatformVersionbehavior when a mock is set. - Mock platform: Implement a fake
ZstandardPlatformthat returns deterministic results and verify that the main plugin (or code under test) behaves correctly when this mock is set asZstandardPlatform.instance.
- Singleton: Verify that
Zstandard()returns the same instance. - Compress/decompress: With a mock platform, verify that
compressanddecompressforward to the platform and return the platform’s result. - Extensions: Test
Uint8List?.compress()anddecompress()with null and non-null receiver, and with a mock platform.
For Android, iOS, and macOS, platform tests are integration tests in example/integration_test/. They include:
- Compression roundtrip: Small, large, and empty input.
- Compression levels: 1, 3, 10, 22.
- Error handling: Corrupted or random bytes for decompress; expect
nullor appropriate handling. - Edge cases: Empty input, highly compressible data, large data.
- Property-based tests: Roundtrip property with generative input (e.g. kiri_check).
- Leak tracking: Where applicable, ensure no leaks after compress/decompress.
Linux and Windows keep unit tests in test/ that run only when the host OS matches. Web tests run in Chrome via flutter test -d chrome.
- The existing tests in
zstandard_cli/test/are a good reference: small/large/empty data, repeated values, min/max compression level. Add tests for invalid compression levels and platform detection if desired.
To collect coverage (when supported):
cd zstandard
flutter test --coverageView the generated coverage/lcov.info with a tool like lcov or your IDE. Aim for high coverage on the main plugin and platform interface; platform-specific code may have lower coverage when run on a single host.
Mutation testing measures test quality by mutating source code and checking whether tests detect the changes. A mutation score of 90% or above is required.
- Config:
mutation_test_config.xmlat repo root (Flutter packages) orzstandard_cli/mutation_test_config.xml(CLI). - Run for one package (from repo root):
cd <package> && dart run mutation_test ../mutation_test_config.xml(usemutation_test_config.xmlfor zstandard_cli). - Run for all packages:
./scripts/run_mutation_test.sh all(takes a long time). - Threshold: Failure if mutation score < 90%.
CI runs platform-specific tests as follows:
- Android: Starts an emulator, runs
zstandard_android/exampleintegration tests, then stops the emulator. - iOS: Boots a simulator, runs
zstandard_ios/exampleintegration tests. - macOS: Builds the native framework (if needed), then runs
zstandard_macos/exampleintegration tests. - Web: Runs
flutter test -d chromein thezstandard_webpackage. - Linux / Windows: Run
flutter teston their respective runners.
Ensure your changes do not break these jobs. Add new tests for new behavior and fix any failing tests before submitting a PR.