Quick Start
Run the main test suite:Test Targets
BuckSample defines multiple test targets inApp/BUCK:
Unit Tests
UnitTests (App/BUCK:349-359): Standard unit tests without a host app
- Tests the
ExampleAppLibraryin isolation - Fast execution
- No simulator UI required
App/BUCK:361-371): Unit tests with a host application
- Runs tests inside the full app context
- Can test app-level integration
- Currently disabled (see TODO in code)
App/BUCK:128-133): Consolidated test bundle for CI
- Bundles all library tests into a single target
- Optimized for continuous integration
- Includes tests from all first-party libraries
UI Tests
XCUITests (App/BUCK:374-395): UI automation tests
- Uses XCUITest framework
- Requires a test host app and target app
- Runs with
fbxctestrunner - Labeled with
uifor filtering
Running Tests
Run unit tests with coverage
Execute the main test suite:This runs:
- Removes old coverage data
- Executes
//App:ExampleAppCITestswith coverage instrumentation - Merges coverage profiles
- Generates a coverage report
Run tests from Xcode
Build and test using the generated Xcode workspace:This command:
- Generates an Xcode project (if needed)
- Runs tests using
xcodebuild - Uses the iPhone 8 simulator
Test Configuration
Unit Tests with Buck
Themake test command uses a detailed configuration:
--test-runner-env: Sets environment variables for the test runnerLLVM_PROFILE_FILE: Configures where code coverage data is written--config-file: Uses code coverage build settings
Code Coverage Configuration
Thecode_coverage.buckconfig file enables coverage instrumentation:
These flags instrument both Objective-C (Clang) and Swift code for coverage tracking.
Code Coverage
Generating Coverage Reports
The test workflow automatically generates coverage reports:Coverage Output Location
Coverage files are stored in:- Raw data:
buck-out/tmp/code-*.profraw - Merged data:
buck-out/gen/Coverage.profdata
UI Test Configuration
Test Structure
UI tests require three components:- XCUITests (
App/BUCK:374-395): The test code itself - XCUITestsHostApp (
App/BUCK:421-433): Launched first in the simulator - ExampleApp (via
ui_test_target_app): The app being tested
Test Host App
The host app is a minimal app bundle required by XCUITest:UI Test Workflow
Themake ui_test command:
Makefile:56-65
Test Discovery
Buck automatically discovers test methods using XCTest conventions:- Methods starting with
testin classes inheriting fromXCTestCase - Works for both Swift and Objective-C tests
Running Specific Tests
Run a Single Test Target
Run Tests Matching a Pattern
Run Tests by Label
Run only UI tests:Xcode Test Integration
To run tests from Xcode:Xcode uses the same test targets defined in BUCK files, ensuring consistency between CLI and IDE testing.
Library Tests
Each first-party library has associated tests. The consolidated CI test target includes://Libraries/ASwiftModule:ASwiftModuleTests//Libraries/Cpp1:Cpp1Tests//Libraries/Objc1:Objc1Tests//Libraries/ObjcAndSwift:ObjcAndSwiftTests//Libraries/SecondSwiftModule:SecondSwiftModuleTests- And more…
Continuous Integration
The complete CI workflow is defined as:install_buck- Ensure Buck is availableinstall_ruby_gems- Install Ruby dependenciestargets- Verify all targets are validbuild- Build the main apptest- Run unit tests with coverageui_test- Run UI testsruby_test- Run Ruby script testsproject- Generate Xcode projectxcode_tests- Run tests in Xcodewatch- Build watch extensionmessage- Build message extension
Ruby Tests
BuckSample includes Ruby-based tests for Buck Local scripts:- Buck Local target parsing
- Project generation logic
- Build script functionality
Troubleshooting
Test Failures
Problem: Tests fail to build- Solution: Clean and rebuild:
make clean && make test
- Solution: Reset the simulator:
- Solution: Ensure
code_coverage.buckconfigis being used and check file permissions inbuck-out/tmp/
Common Issues
Problem: “No tests ran” message- Solution: Verify test methods start with
testand the class inherits fromXCTestCase
- Solution: List available simulators:
Update the
TARGET_SIMULATORvariable in Makefile
- Solution: Tests may be defined with
run_test_separately = True, which requires special test runners
Next Steps
Building the App
Learn about build commands and configurations
Xcode Projects
Generate Xcode projects for IDE development