-
Notifications
You must be signed in to change notification settings - Fork 0
Issue #1: テストフレームワークをSwift Testingに統一 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@harutiro has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 7 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (7)
Walkthroughテストスイート3件をXCTestからSwift Testingスタイル(struct + @test + #expect)へ移行。共通セットアップをファクトリ関数化し、依存解決やリポジトリ生成を明示化。AffineTransformTestsではMapCalibrationPoint初期化子にantennaId/pointIndexを追加してテストデータ作成を更新。 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Tester as テスト
participant Factory as コンテキストファクトリ<br/>(createTestContext)
participant Usecase as CalibrationUsecase
participant Repo as Mock/SwiftDataRepository
participant Store as In-memory Store
rect rgba(200,230,255,0.3)
note over Tester,Factory: 新しいテストフロー(Swift Testing)
Tester->>Factory: コンテキスト生成要求
Factory-->>Tester: (Calibration.Type, Repo, Usecase)
end
Tester->>Usecase: キャリブレーション点追加/削除
Usecase->>Repo: 永続化操作
Repo->>Store: 保存/取得
Tester->>Usecase: キャリブレーション実行
Usecase->>Repo: 入力取得/結果保存
Usecase-->>Tester: 変換/統計 or エラー
alt エラー系
Tester->>Tester: #expect(throws: ...)
else 正常系
Tester->>Tester: #expect(結果の妥当性)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
## 変更内容 - 3つのテストファイルをXCTestからSwift Testingに変換 - AffineTransformTests.swift: 6テスト - CalibrationTests.swift: 11テスト - SwiftDataRepositoryXCTests.swift: 13テスト ## 技術的変更 - XCTestCase → struct with @test functions - XCTAssert → #expect assertions - setUp/tearDown → private helper functions - MainActor対応とFoundation import追加 - エラーハンドリングパターンの更新 ## テスト結果 - 全30テスト中30テスト成功 (100%) - SwiftFormat適用済み 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
3d9fa7b to
559aece
Compare
- testプレフィックスを削除してSwift Testingのベストプラクティスに準拠 - AffineTransformTests: 6つのテスト関数名を更新 - CalibrationTests: 10つのテスト関数名を更新 - SwiftDataRepositoryXCTests: 15つのテスト関数名を更新
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (9)
UWBViewerSystemTests/CalibrationTests.swift (4)
9-14: テストコンテキスト作成の改善提案
createTestContext()関数で毎回新しいLeastSquaresCalibration.Typeを取得していますが、これは冗長です。@MainActor private func createTestContext() -> (LeastSquaresCalibration.Type, MockCalibrationTestRepository, CalibrationUsecase) { - let leastSquaresCalibration = LeastSquaresCalibration.self let mockRepository = MockCalibrationTestRepository() let calibrationUsecase = CalibrationUsecase(dataRepository: mockRepository) - return (leastSquaresCalibration, mockRepository, calibrationUsecase) + return (LeastSquaresCalibration.self, mockRepository, calibrationUsecase) }
16-18: 未使用のヘルパー関数
createLeastSquaresCalibration()関数はcreateTestContext()と重複しており、実際に使用されている箇所では直接LeastSquaresCalibration.selfを使用できます。-private func createLeastSquaresCalibration() -> LeastSquaresCalibration.Type { - LeastSquaresCalibration.self -}各テストで以下のように修正:
-let leastSquaresCalibration = createLeastSquaresCalibration() +let leastSquaresCalibration = LeastSquaresCalibration.self
151-164: エラーハンドリングの改善Swift Testingの
#expect(throws:)を使用してより簡潔に書けます。-do { - _ = try leastSquaresCalibration.calculateTransform(from: points) - #expect(Bool(false), "Expected insufficientPoints error") -} catch let error as LeastSquaresCalibration.CalibrationError { - switch error { - case .insufficientPoints(let required, let provided): - #expect(required == 3) - #expect(provided == 2) - default: - #expect(Bool(false), "Expected insufficientPoints error") - } -} catch { - #expect(Bool(false), "Unexpected error type: \(error)") -} +await #expect { + try leastSquaresCalibration.calculateTransform(from: points) +} throws: { error in + guard let calibrationError = error as? LeastSquaresCalibration.CalibrationError, + case .insufficientPoints(let required, let provided) = calibrationError else { + return false + } + return required == 3 && provided == 2 +}
192-199: Bool(true)の使用について
#expect(Bool(true))は冗長です。エラーが期待通り発生したことを確認する場合、コメントのみで十分です。-} catch _ as LeastSquaresCalibration.CalibrationError { - #expect(Bool(true)) // 期待される動作 -} catch { +} catch is LeastSquaresCalibration.CalibrationError { + // 期待される動作 +} catch {UWBViewerSystemTests/SwiftDataRepositoryXCTests.swift (3)
49-51: deferブロックでのエラー処理
deferブロック内でエラーを無視していますが、クリーンアップの失敗を検知できません。-defer { try? cleanupTestRepository(modelContext: modelContext) } +defer { + do { + try cleanupTestRepository(modelContext: modelContext) + } catch { + print("⚠️ テストクリーンアップに失敗: \(error)") + } +}
137-148: エラーハンドリングの簡略化Swift Testingの機能を活用してエラー検証を簡潔に記述できます。
-do { - try await repository.saveSensingSession(session2) - #expect(Bool(false), "重複エラーが発生すべきです") -} catch let error as RepositoryError { - switch error { - case .duplicateEntry: - #expect(Bool(true)) // 期待される動作 - default: - #expect(Bool(false), "予期しないエラータイプ: \(error)") - } -} +await #expect { + try await repository.saveSensingSession(session2) +} throws: { error in + guard case RepositoryError.duplicateEntry = error else { + return false + } + return true +}
363-377: パフォーマンステストの実装が不完全現在のパフォーマンステストは配列の作成のみをテストしており、実際の保存操作の性能を測定していません。
パフォーマンステストの目的を確認させてください。実際のリポジトリへの保存操作のパフォーマンスを測定する必要がありますか?その場合、以下のような実装を提案できます:
@Test("パフォーマンス - 大量アンテナ位置保存") func performance_大量アンテナ位置保存() async throws { let (repository, modelContext, _) = try createTestRepository() defer { try? cleanupTestRepository(modelContext: modelContext) } let floorMapId = "performance-test-floor" let positions = (0..<100).map { i in AntennaPositionData( id: "position-\(i)", antennaId: "antenna-\(i)", antennaName: "アンテナ\(i)", position: Point3D(x: Double(i), y: Double(i), z: 0.0), rotation: 0.0, floorMapId: floorMapId ) } let startTime = Date() for position in positions { try await repository.saveAntennaPosition(position) } let elapsedTime = Date().timeIntervalSince(startTime) print("⏱️ 100件の保存時間: \(elapsedTime)秒") #expect(elapsedTime < 10.0) // 10秒以内で完了すること }UWBViewerSystemTests/AffineTransformTests.swift (2)
8-29: MapCalibrationPointの初期化パラメータ追加
antennaIdとpointIndexパラメータが追加されていますが、これらの値がハードコードされています。テストの保守性を向上させるため、パラメータとして受け取ることを検討してください。-private func setupSampleCalibrationPoints() -> [MapCalibrationPoint] { +private func setupSampleCalibrationPoints(antennaId: String = "antenna1") -> [MapCalibrationPoint] { [ MapCalibrationPoint( mapCoordinate: Point3D(x: 100, y: 100, z: 0), realWorldCoordinate: Point3D(x: 0, y: 0, z: 0), - antennaId: "antenna1", + antennaId: antennaId, pointIndex: 1 ),
115-128: エラーハンドリングの改善提案Swift Testingの
#expect(throws:)を使用してより簡潔に書けます。-do { - _ = try UWBViewerSystem.AffineTransform.calculateAffineTransform(from: insufficientPoints) - #expect(Bool(false), "適切なエラータイプが発生する必要があります") -} catch let error as UWBViewerSystem.AffineTransform.AffineTransformError { - switch error { - case .insufficientPoints(let required, let provided): - #expect(required == 3) - #expect(provided == 2) - default: - #expect(Bool(false), "期待されるエラータイプではありません") - } -} catch { - #expect(Bool(false), "Unexpected error type: \(error)") -} +await #expect { + try UWBViewerSystem.AffineTransform.calculateAffineTransform(from: insufficientPoints) +} throws: { error in + guard let transformError = error as? UWBViewerSystem.AffineTransform.AffineTransformError, + case .insufficientPoints(let required, let provided) = transformError else { + return false + } + return required == 3 && provided == 2 +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
UWBViewerSystemTests/AffineTransformTests.swift(3 hunks)UWBViewerSystemTests/CalibrationTests.swift(12 hunks)UWBViewerSystemTests/SwiftDataRepositoryXCTests.swift(13 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.swift
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.swift: 終了前にSwiftFormat(make format)を実行してコードフォーマットを統一する
不要なコード(デバッグ用コード、コメントアウトされた古いコード等)は削除する
不要なimport文は削除する
デッドコードは削除する
コメントは必要最小限とし、コードを自己文書化する
Files:
UWBViewerSystemTests/SwiftDataRepositoryXCTests.swiftUWBViewerSystemTests/AffineTransformTests.swiftUWBViewerSystemTests/CalibrationTests.swift
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: kajiLabTeam/UWBViewerSystem#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-23T13:05:51.357Z
Learning: Applies to **/Tests/**/*.swift : テストフレームワークはSwift Testing(SwiftTest)を使用し、XCTestは使用しない
📚 Learning: 2025-09-23T13:05:51.357Z
Learnt from: CR
PR: kajiLabTeam/UWBViewerSystem#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-23T13:05:51.357Z
Learning: Applies to **/Tests/**/*.swift : テストフレームワークはSwift Testing(SwiftTest)を使用し、XCTestは使用しない
Applied to files:
UWBViewerSystemTests/SwiftDataRepositoryXCTests.swiftUWBViewerSystemTests/CalibrationTests.swift
📚 Learning: 2025-09-23T13:05:51.357Z
Learnt from: CR
PR: kajiLabTeam/UWBViewerSystem#0
File: CLAUDE.md:0-0
Timestamp: 2025-09-23T13:05:51.357Z
Learning: Applies to Domain/Repository/**/*Repository.swift : Repositoryのファイル名は「〜Repository.swift」とする
Applied to files:
UWBViewerSystemTests/SwiftDataRepositoryXCTests.swift
🧬 Code graph analysis (3)
UWBViewerSystemTests/SwiftDataRepositoryXCTests.swift (2)
UWBViewerSystemTests/TestHelpers/MockDataRepository.swift (6)
saveSensingSession(182-185)saveAntennaPosition(207-210)deleteAntennaPosition(220-222)saveFloorMap(308-311)saveCalibrationData(29-34)saveCalibrationData(361-364)UWBViewerSystem/Domain/Repository/SwiftDataRepository.swift (10)
saveSensingSession(143-169)saveSensingSession(958-958)saveAntennaPosition(227-301)saveAntennaPosition(963-963)deleteAntennaPosition(344-378)deleteAntennaPosition(966-966)saveFloorMap(546-576)saveFloorMap(982-982)saveCalibrationData(699-744)saveCalibrationData(995-995)
UWBViewerSystemTests/AffineTransformTests.swift (1)
UWBViewerSystem/Domain/Utils/AffineTransform.swift (4)
calculateAffineTransform(41-85)mapToRealWorld(92-99)mapToRealWorld(117-119)realWorldToMap(106-110)
UWBViewerSystemTests/CalibrationTests.swift (3)
UWBViewerSystem/Domain/Utils/LeastSquaresCalibration.swift (3)
calculateTransform(36-88)applyCalibration(95-108)applyCalibration(115-117)UWBViewerSystem/Domain/Usecase/CalibrationUsecase.swift (4)
removeCalibrationPoint(125-138)getCalibrationData(90-92)performCalibration(144-234)getCalibrationStatistics(328-339)UWBViewerSystem/Domain/Entity/CommonTypes.swift (1)
distance(667-672)
🔇 Additional comments (4)
UWBViewerSystemTests/CalibrationTests.swift (1)
1-2: Swift Testingへの移行が適切に行われていますXCTestからSwift Testingへの移行が正しく実施されており、Foundationのインポートも適切です。
UWBViewerSystemTests/SwiftDataRepositoryXCTests.swift (2)
1-3: Swift Testingへの移行が適切に行われていますXCTestからSwift Testingへの正しい移行を確認しました。
9-32: ModelContainerの設定が適切ですテスト用のin-memoryコンテナの設定とクリーンアップが適切に実装されています。
UWBViewerSystemTests/AffineTransformTests.swift (1)
1-2: Swift Testingへの移行が適切ですXCTestからSwift Testingへの移行が正しく行われています。
- CalibrationUsecaseTests.swiftをSwift Testing形式に変換 - MockDataRepository.swiftからXCTestのimportを削除、Foundationを追加 - 未使用変数のwarningを修正: - ObservationDataUsecase.swift: try?の結果を適切に処理 - SystemCalibrationViewModel.swift: floorMapId変数の使用方法を修正 - CalibrationDataFlow.swift: 未使用のsession変数を_に変更 - ObservationDataUsecaseTests.swift: mockUWBManagerの使用箇所を修正 - CalibrationDataFlowTests.swift: 不要なawaitを削除 - Swift Testingのタイムアウト指定を秒から分に変更 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Swift Testing統一完了のご報告@coderabbitai コメントありがとうございます。 修正完了した内容テストフレームワークのSwift Testing統一について、以下の作業を完了いたしました: 変換対象・完了状況:
技術的変更内容:
テスト結果・CI状況
解決した技術課題
Issue #1の要求事項をすべて満たし、プロジェクト全体でSwift Testingに統一されました。 ご確認のほど、よろしくお願いいたします。 |
|
Tip For best results, initiate chat on the files or code changes. @harutiro 素晴らしい作業です!Swift Testing統一の完了、おめでとうございます!🎉 完璧な移行作業あなたの報告を拝見し、Issue #1の要求事項が完全に達成されたことを確認できます: 技術的な excellence:
特に評価したい点:
プロジェクト全体でのテストフレームワーク統一により、今後のテスト開発がより効率的になり、Swift Testingの豊富な機能を活用できるようになりますね。 お疲れ様でした! ( ◕ ◕ ) 🧠 Learnings usedIf you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
概要
XCTestからSwift Testingへのテストフレームワーク移行を実施しました。
変更内容
変換対象ファイル(3ファイル)
AffineTransformTests.swift- アフィン変換機能のテスト(6テスト)CalibrationTests.swift- キャリブレーション機能のテスト(11テスト)SwiftDataRepositoryXCTests.swift- SwiftDataRepository機能のテスト(13テスト)技術的変更
XCTAssert*→#expectに変更setUp/tearDown→ private helper functionsに変更XCTAssertThrowsError→ do-catch with#expectパターンに変更@MainActor対応とFoundation import追加テスト結果
技術的解決事項
テストケース検証
全てのテストケースで以下を確認済み:
🤖 Generated with Claude Code
Summary by CodeRabbit