Upgrade to Pro — share decks privately, control downloads, hide ads and more …

マルチモジュールにおけるテスト最適化

fxwx23
September 02, 2024

 マルチモジュールにおけるテスト最適化

fxwx23

September 02, 2024
Tweet

More Decks by fxwx23

Other Decks in Programming

Transcript

  1. 自己紹介 • Fumitaka Watanabe ◦ @fxwx23 • 株式会社はてな ◦ マンガアプリチーム

    ◦ GigaViewer for Apps [1] [1] https://hatena.co.jp/solutions/gigaviewer
  2. Xcodeプロジェクト内のターゲット間 の依存関係 • App.xcworkspace > App.xcproj > project.pbxproj > PBXTarget

    > PBXNativeTarget > dependencies http://www.monobjc.net/xcode-project-file-format.html
  3. • App.xcworkspace > App.xcproj > project.pbxproj > PBXTarget > PBXNativeTarget

    > dependencies 491FBA866697560BBEF6A475 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 3478A70B9E3147C13F640454 /* AModule */; }; 4C4FDDD28591957330786D9B /* App */ = { isa = PBXNativeTarget; dependencies = ( 491FBA866697560BBEF6A475 /* PBXTargetDependency */ ); } http://www.monobjc.net/xcode-project-file-format.html Xcodeプロジェクト内のターゲット間 の依存関係
  4. • App.xcworkspace > App.xcproj > project.pbxproj > PBXTarget > PBXNativeTarget

    > dependencies 491FBA866697560BBEF6A475 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 3478A70B9E3147C13F640454 /* AModule */; }; 4C4FDDD28591957330786D9B /* App */ = { isa = PBXNativeTarget; dependencies = ( 491FBA866697560BBEF6A475 /* PBXTargetDependency */ ); } http://www.monobjc.net/xcode-project-file-format.html Xcodeプロジェクト内のターゲット間 の依存関係
  5. ターゲットとSwift Package間の依存 4C4FDDD28591957330786D9B /* AModule */ = { isa =

    PBXNativeTarget; packageProductDependencies = ( 1885F5AAE69D8D13E59C4ECF /* BModule */, ); }; http://www.monobjc.net/xcode-project-file-format.html • App.xcworkspace > App.xcproj > project.pbxproj > PBXTarget > PBXNativeTarget > packageProductDependencies
  6. Swift Package 内でのターゲット間の 依存 • $ swift package dump-package {

    "targets": [ { "dependencies": [ { "byName": ["CModule", null] } ], "name": "BModule" } ] }
  7. XcodeSelectiveTesting • $ swift run xcode-selective-testing --test-plan App.xctestplan • $

    swift run xcode-selective-testing --json https://github.com/mikeger/XcodeSelectiveTesting
  8. JSON Output [ { "name": "AppTests", "type": "target", "path": "\/path\/to\/your\/App.xcodeproj",

    "testTarget": true }, { "name": "App", "type": "target", "path": "\/path\/to\/your\/App.xcodeproj", "testTarget": false } ]
  9. JSON Output [ { "name": "AppTests", "type": "target", "path": "\/path\/to\/your\/App.xcodeproj",

    "testTarget": true }, { "name": "App", "type": "target", "path": "\/path\/to\/your\/App.xcodeproj", "testTarget": false } ] $ jq -r "[.[] | select(.testTarget == true)] | map(.name) | join(\",\")"
  10. JSON Output [ { "name": "AppTests", "type": "target", "path": "\/path\/to\/your\/App.xcodeproj",

    "testTarget": true }, { "name": "App", "type": "target", "path": "\/path\/to\/your\/App.xcodeproj", "testTarget": false } ] $ jq -r "[.[] | select(.testTarget == true)] | map(.name) | join(\",\")" AppTests
  11. fastlane lane :selective_test do |options| if options[:targets].nil? then UI.user_error!("The required

    parameter is invalid or missing.") end if options[:targets].empty? then UI.user_error!("At least one target is required.") end run_tests( scheme: "...", only_testing: options[:targets], ) end
  12. fastlane TARGETS=$(./scripts/affected-targets.sh) if [ -n "$TARGETS" ]; then bundle exec

    fastlane selective_test targets:"$TARGETS" else bundle exec fastlane test fi https://fxwx23.hatenablog.com/entry/tips-integrating-xcode-selective-testing
  13. フルテスト +-------------------------------+ | Test Results | +-------------------------+-----+ | Number of

    tests | 674 | | Number of failures | 0 | +-------------------------+-----+
  14. フルテスト +-------------------------------+ | Test Results | +-------------------------+-----+ | Number of

    tests | 15 | | Number of failures | 0 | +-------------------------+-----+ +-------------------------------+ | Test Results | +-------------------------+-----+ | Number of tests | 674 | | Number of failures | 0 | +-------------------------+-----+ Application Target 変更の み
  15. 💪 フルテスト +-------------------------------+ | Test Results | +-------------------------+-----+ | Number

    of tests | 15 | | Number of failures | 0 | +-------------------------+-----+ +-------------------------------+ | Test Results | +-------------------------+-----+ | Number of tests | 674 | | Number of failures | 0 | +-------------------------+-----+ Application Target 変更の み