@k2works/claude-code-booster 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. package/README.md +14 -0
  2. package/bin/claude-code-booster +39 -16
  3. package/lib/assets/.claude/README.md +44 -40
  4. package/lib/assets/.claude/commands/analysis.md +230 -0
  5. package/lib/assets/.claude/commands/kill.md +109 -0
  6. package/lib/assets/.claude/commands/next.md +136 -0
  7. package/lib/assets/.claude/commands/plan.md +141 -91
  8. package/lib/assets/.claude/commands/progress.md +172 -0
  9. package/lib/assets/docs/reference/UI/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +446 -0
  10. package/lib/assets/docs/reference//343/202/242/343/203/274/343/202/255/343/203/206/343/202/257/343/203/201/343/203/243/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +1428 -0
  11. package/lib/assets/docs/reference//343/202/244/343/203/263/343/203/225/343/203/251/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +1879 -0
  12. package/lib/assets/docs/reference//343/203/206/343/202/271/343/203/210/346/210/246/347/225/245/343/202/254/343/202/244/343/203/211.md +1310 -0
  13. package/lib/assets/docs/reference//343/203/207/343/203/274/343/202/277/343/203/242/343/203/207/343/203/253/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +312 -0
  14. package/lib/assets/docs/reference//343/203/211/343/203/241/343/202/244/343/203/263/343/203/242/343/203/207/343/203/253/350/250/255/350/250/210/343/202/254/343/202/244/343/203/211.md +600 -0
  15. package/lib/assets/docs/reference//343/203/246/343/203/274/343/202/271/343/202/261/343/203/274/343/202/271/344/275/234/346/210/220/343/202/254/343/202/244/343/203/211.md +672 -0
  16. package/lib/assets/docs/reference//343/203/252/343/203/252/343/203/274/343/202/271/343/203/273/343/202/244/343/203/206/343/203/254/343/203/274/343/202/267/343/203/247/343/203/263/350/250/210/347/224/273/343/202/254/343/202/244/343/203/211.md +524 -0
  17. package/lib/assets/docs/reference//351/201/213/347/224/250/350/246/201/344/273/266/345/256/232/347/276/251/343/202/254/343/202/244/343/203/211.md +393 -0
  18. package/lib/assets/docs/reference//351/226/213/347/231/272/343/202/254/343/202/244/343/203/211.md +18 -173
  19. package/lib/assets/docs/reference//351/235/236/346/251/237/350/203/275/350/246/201/344/273/266/345/256/232/347/276/251/343/202/254/343/202/244/343/203/211.md +1231 -0
  20. package/lib/assets/docs/template//345/256/214/345/205/250/345/275/242/345/274/217/343/201/256/343/203/246/343/203/274/343/202/271/343/202/261/343/203/274/343/202/271.md +64 -0
  21. package/lib/assets/docs/template//350/246/201/344/273/266/345/256/232/347/276/251.md +467 -443
  22. package/package.json +1 -1
@@ -0,0 +1,1310 @@
1
+ # テスト戦略ガイド
2
+
3
+ ## 概要
4
+
5
+ よいソフトウェアを作るためのテスト戦略について説明する。アーキテクチャパターンに応じた適切なテスト戦略を選択し、変更を楽に安全にできて役に立つソフトウェアの実現を目指す。
6
+
7
+ ## テスト戦略の基本原則
8
+
9
+ ### よいソフトウェアとテスト
10
+
11
+ 変更を楽に安全にできて役に立つソフトウェアを作るため、テストは以下の価値を提供する:
12
+
13
+ 1. **安全な変更**: 既存機能を破壊することなく新機能を追加
14
+ 2. **設計の改善**: テスタブルなコードは良い設計の指標
15
+ 3. **ドキュメント**: テストコードは実行可能な仕様書
16
+ 4. **品質の保証**: バグの早期発見と予防
17
+
18
+ ### テスト駆動開発(TDD)
19
+
20
+ ```plantuml
21
+ @startuml
22
+ [*] --> Red
23
+ Red --> Green : テストを通す最小実装
24
+ Green --> Refactor : リファクタリング
25
+ Refactor --> Red : 次のテスト
26
+ Red : 失敗するテストを書く
27
+ Green : テストが通る実装
28
+ Refactor : 重複を除去し設計を改善
29
+ @enduml
30
+ ```
31
+
32
+ #### TDD の 3 つの法則
33
+
34
+ 1. **失敗する単体テストを書くまでプロダクションコードを書かない**
35
+ 2. **コンパイルが通らない、または失敗する範囲を超えて単体テストを書かない**
36
+ 3. **現在失敗している単体テストを通す以上にプロダクションコードを書かない**
37
+
38
+ ## テスト形態とアーキテクチャパターン
39
+
40
+ アーキテクチャパターンに応じて、最適なテスト形態を選択する。
41
+
42
+ ### ピラミッド形テスト
43
+
44
+ ```plantuml
45
+ @startuml
46
+ !define PRIMARY_COLOR #1E88E5
47
+ !define SECONDARY_COLOR #FFC107
48
+ !define SUCCESS_COLOR #4CAF50
49
+
50
+ rectangle "E2Eテスト (5%)" as E2E SUCCESS_COLOR {
51
+ note as E2ENote
52
+ - ユーザーシナリオテスト
53
+ - 実環境に近い状態
54
+ - 性能テスト
55
+ end note
56
+ }
57
+
58
+ rectangle "統合テスト (15%)" as Integration SECONDARY_COLOR {
59
+ note as IntegrationNote
60
+ - コンポーネント間の連携
61
+ - APIの検証
62
+ - データフローの確認
63
+ end note
64
+ }
65
+
66
+ rectangle "ユニットテスト (80%)" as Unit PRIMARY_COLOR {
67
+ note as UnitNote
68
+ - 個々のコンポーネント
69
+ - ビジネスロジック
70
+ - 境界値テスト
71
+ end note
72
+ }
73
+
74
+ E2E -[hidden]down-> Integration
75
+ Integration -[hidden]down-> Unit
76
+ @enduml
77
+ ```
78
+
79
+ #### 適用対象
80
+ - **ドメインモデルパターン**
81
+ - **イベント履歴式**
82
+ - **ヘキサゴナルアーキテクチャ**
83
+
84
+ #### 特徴
85
+ - **ユニットテストに重点**: 高品質なビジネスロジックの検証
86
+ - **高速なフィードバック**: 素早いテスト実行
87
+ - **保守コストが低い**: シンプルで理解しやすいテスト
88
+
89
+ #### 実装例
90
+
91
+ **ドメインモデルのユニットテスト**
92
+ ```java
93
+ @Test
94
+ void 予約をキャンセルできる() {
95
+ // Given
96
+ TimeSlot futureTimeSlot = createFutureTimeSlot();
97
+ Reservation reservation = Reservation.create(
98
+ UserId.generate(), RoomId.generate(),
99
+ new ReservationTitle("会議"), new Purpose("定例会議"), futureTimeSlot);
100
+
101
+ // When
102
+ reservation.cancel();
103
+
104
+ // Then
105
+ assertThat(reservation.getStatus()).isEqualTo(ReservationStatus.CANCELLED);
106
+ }
107
+
108
+ @Test
109
+ void 開始2時間前を過ぎた予約はキャンセルできない() {
110
+ // Given
111
+ TimeSlot pastTimeSlot = createPastTimeSlot();
112
+ Reservation reservation = Reservation.create(
113
+ UserId.generate(), RoomId.generate(),
114
+ new ReservationTitle("会議"), new Purpose("定例会議"), pastTimeSlot);
115
+
116
+ // When & Then
117
+ assertThatThrownBy(reservation::cancel)
118
+ .isInstanceOf(IllegalStateException.class)
119
+ .hasMessageContaining("2時間前まで");
120
+ }
121
+ ```
122
+
123
+ ### ダイヤモンド形テスト
124
+
125
+ ```plantuml
126
+ @startuml
127
+ !define PRIMARY_COLOR #1E88E5
128
+ !define SECONDARY_COLOR #FFC107
129
+ !define SUCCESS_COLOR #4CAF50
130
+
131
+ rectangle "E2Eテスト (20%)" as E2E SUCCESS_COLOR {
132
+ note as E2ENote
133
+ - ユーザーシナリオテスト
134
+ - エンドツーエンド検証
135
+ end note
136
+ }
137
+
138
+ rectangle "統合テスト (50%)" as Integration SECONDARY_COLOR {
139
+ note as IntegrationNote
140
+ - データアクセス層の検証
141
+ - トランザクション境界のテスト
142
+ - 複数コンポーネント連携
143
+ end note
144
+ }
145
+
146
+ rectangle "ユニットテスト (30%)" as Unit PRIMARY_COLOR {
147
+ note as UnitNote
148
+ - ビジネスロジック
149
+ - バリデーション
150
+ - 基本的なCRUD操作
151
+ end note
152
+ }
153
+
154
+ E2E -[hidden]down-> Integration
155
+ Integration -[hidden]down-> Unit
156
+ @enduml
157
+ ```
158
+
159
+ #### 適用対象
160
+ - **アクティブレコードパターン**
161
+ - **レイヤードアーキテクチャ(データベース中心)**
162
+
163
+ #### 特徴
164
+ - **統合テストに重点**: データアクセスロジックの検証
165
+ - **データベーステスト**: 実際のデータベース操作を含む
166
+ - **中程度の実行速度**: データベースアクセスを含むため
167
+
168
+ #### 実装例
169
+
170
+ **データアクセス層の統合テスト**
171
+ ```java
172
+ @SpringBootTest
173
+ @Testcontainers
174
+ @Transactional
175
+ class ReservationRepositoryTest {
176
+
177
+ @Container
178
+ static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15");
179
+
180
+ @Autowired
181
+ private ReservationRepository reservationRepository;
182
+
183
+ @Test
184
+ void 予約を保存して取得できる() {
185
+ // Given
186
+ Reservation reservation = createTestReservation();
187
+
188
+ // When
189
+ reservationRepository.save(reservation);
190
+ Optional<Reservation> found = reservationRepository.findById(reservation.getId());
191
+
192
+ // Then
193
+ assertThat(found).isPresent();
194
+ assertThat(found.get().getTitle()).isEqualTo(reservation.getTitle());
195
+ }
196
+
197
+ @Test
198
+ void アクティブな予約のみ取得される() {
199
+ // Given
200
+ Reservation activeReservation = createActiveReservation();
201
+ Reservation cancelledReservation = createCancelledReservation();
202
+ reservationRepository.save(activeReservation);
203
+ reservationRepository.save(cancelledReservation);
204
+
205
+ // When
206
+ List<Reservation> activeReservations = reservationRepository.findActiveByUserId(
207
+ activeReservation.getUserId());
208
+
209
+ // Then
210
+ assertThat(activeReservations).hasSize(1);
211
+ assertThat(activeReservations.get(0).getId()).isEqualTo(activeReservation.getId());
212
+ }
213
+ }
214
+ ```
215
+
216
+ ### 逆ピラミッド形テスト
217
+
218
+ ```plantuml
219
+ @startuml
220
+ !define PRIMARY_COLOR #1E88E5
221
+ !define SECONDARY_COLOR #FFC107
222
+ !define SUCCESS_COLOR #4CAF50
223
+
224
+ rectangle "E2Eテスト (70%)" as E2E SUCCESS_COLOR {
225
+ note as E2ENote
226
+ - ユーザーシナリオテスト
227
+ - ワークフロー全体の検証
228
+ - UIからデータベースまで
229
+ end note
230
+ }
231
+
232
+ rectangle "統合テスト (20%)" as Integration SECONDARY_COLOR {
233
+ note as IntegrationNote
234
+ - API レベルの検証
235
+ - サービス間連携
236
+ end note
237
+ }
238
+
239
+ rectangle "ユニットテスト (10%)" as Unit PRIMARY_COLOR {
240
+ note as UnitNote
241
+ - バリデーション
242
+ - ユーティリティ関数
243
+ - 計算ロジック
244
+ end note
245
+ }
246
+
247
+ E2E -[hidden]down-> Integration
248
+ Integration -[hidden]down-> Unit
249
+ @enduml
250
+ ```
251
+
252
+ #### 適用対象
253
+ - **トランザクションスクリプトパターン**
254
+ - **単純なCRUDアプリケーション**
255
+
256
+ #### 特徴
257
+ - **E2Eテストに重点**: エンドツーエンドの動作検証
258
+ - **ユーザー視点**: 実際のユーザー操作をシミュレート
259
+ - **低速だが包括的**: 全体的な動作を保証
260
+
261
+ #### 実装例
262
+
263
+ **E2Eテスト(Selenium WebDriver使用)**
264
+ ```java
265
+ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
266
+ @Testcontainers
267
+ class ReservationE2ETest {
268
+
269
+ @Container
270
+ static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15");
271
+
272
+ @Autowired
273
+ private TestRestTemplate restTemplate;
274
+
275
+ private WebDriver driver;
276
+
277
+ @BeforeEach
278
+ void setUp() {
279
+ driver = new ChromeDriver();
280
+ }
281
+
282
+ @Test
283
+ void 会議室を検索して予約できる() {
284
+ // Given - ユーザーがログイン済み
285
+ loginAsTestUser();
286
+
287
+ // When - 会議室検索ページにアクセス
288
+ driver.get("http://localhost:" + port + "/rooms/search");
289
+
290
+ // 検索条件を入力
291
+ driver.findElement(By.id("capacity")).sendKeys("10");
292
+ driver.findElement(By.id("date")).sendKeys("2024-12-01");
293
+ driver.findElement(By.id("startTime")).sendKeys("10:00");
294
+ driver.findElement(By.id("endTime")).sendKeys("12:00");
295
+ driver.findElement(By.id("searchButton")).click();
296
+
297
+ // 検索結果から会議室を選択
298
+ WebElement roomCard = driver.findElement(By.className("room-card"));
299
+ roomCard.findElement(By.className("reserve-button")).click();
300
+
301
+ // 予約情報を入力
302
+ driver.findElement(By.id("title")).sendKeys("定例会議");
303
+ driver.findElement(By.id("purpose")).sendKeys("週次定例会議");
304
+ driver.findElement(By.id("submitButton")).click();
305
+
306
+ // Then - 予約完了メッセージが表示される
307
+ WebElement successMessage = driver.findElement(By.className("success-message"));
308
+ assertThat(successMessage.getText()).contains("予約が完了しました");
309
+ }
310
+
311
+ @Test
312
+ void 予約をキャンセルできる() {
313
+ // Given - 事前に予約を作成
314
+ createTestReservation();
315
+ loginAsTestUser();
316
+
317
+ // When - マイ予約ページにアクセス
318
+ driver.get("http://localhost:" + port + "/my-reservations");
319
+
320
+ // 予約をキャンセル
321
+ WebElement reservationCard = driver.findElement(By.className("reservation-card"));
322
+ reservationCard.findElement(By.className("cancel-button")).click();
323
+
324
+ // 確認ダイアログでOK
325
+ driver.switchTo().alert().accept();
326
+
327
+ // Then - キャンセル済み表示になる
328
+ WebElement status = reservationCard.findElement(By.className("status"));
329
+ assertThat(status.getText()).isEqualTo("キャンセル済み");
330
+ }
331
+ }
332
+ ```
333
+
334
+ ## 会議室予約システムのテスト戦略
335
+
336
+ ### アーキテクチャとテスト戦略の選択
337
+
338
+ 会議室予約システムは**ドメインモデルパターン**と**ヘキサゴナルアーキテクチャ**を採用するため、**ピラミッド形テスト**が最適。
339
+
340
+ ```plantuml
341
+ @startuml
342
+ !define DOMAIN_COLOR #9C27B0
343
+ !define APP_COLOR #4CAF50
344
+ !define INFRA_COLOR #FF9800
345
+
346
+ package "ドメイン層" as Domain DOMAIN_COLOR {
347
+ [User]
348
+ [Room]
349
+ [Reservation]
350
+ [ConflictChecker]
351
+ [ReservationLimitChecker]
352
+ }
353
+
354
+ package "アプリケーション層" as App APP_COLOR {
355
+ [CreateReservationUseCase]
356
+ [CancelReservationUseCase]
357
+ [SearchRoomsUseCase]
358
+ }
359
+
360
+ package "インフラストラクチャ層" as Infra INFRA_COLOR {
361
+ [ReservationController]
362
+ [ReservationRepository]
363
+ [UserRepository]
364
+ [RoomRepository]
365
+ }
366
+
367
+ note right of Domain
368
+ **ユニットテスト (80%)**
369
+ - 値オブジェクト
370
+ - エンティティ
371
+ - ドメインサービス
372
+ - 集約のビジネスルール
373
+ end note
374
+
375
+ note right of App
376
+ **統合テスト (15%)**
377
+ - ユースケースの組み合わせ
378
+ - トランザクション境界
379
+ - ドメインサービス連携
380
+ end note
381
+
382
+ note right of Infra
383
+ **E2Eテスト (5%)**
384
+ - APIエンドポイント
385
+ - ユーザーシナリオ
386
+ - システム全体の動作
387
+ end note
388
+ @enduml
389
+ ```
390
+
391
+ ### テストレベル別の詳細戦略
392
+
393
+ #### レベル1:ユニットテスト(80%)
394
+
395
+ **対象**:ドメイン層の各コンポーネント
396
+
397
+ **値オブジェクトのテスト**
398
+ ```java
399
+ class TimeSlotTest {
400
+ @Test
401
+ void 有効な時間枠で作成できる() {
402
+ LocalDateTime start = LocalDateTime.of(2024, 1, 1, 10, 0);
403
+ LocalDateTime end = LocalDateTime.of(2024, 1, 1, 12, 0);
404
+
405
+ assertThatCode(() -> new TimeSlot(start, end))
406
+ .doesNotThrowAnyException();
407
+ }
408
+
409
+ @Test
410
+ void 営業時間外は例外が発生する() {
411
+ LocalDateTime start = LocalDateTime.of(2024, 1, 1, 7, 0); // 営業時間前
412
+ LocalDateTime end = LocalDateTime.of(2024, 1, 1, 9, 0);
413
+
414
+ assertThatThrownBy(() -> new TimeSlot(start, end))
415
+ .isInstanceOf(IllegalArgumentException.class)
416
+ .hasMessageContaining("営業時間内");
417
+ }
418
+
419
+ @ParameterizedTest
420
+ @CsvSource({
421
+ "10:00, 12:00, 11:00, 13:00, true", // 重複あり
422
+ "10:00, 12:00, 12:00, 14:00, false", // 重複なし(境界)
423
+ "10:00, 12:00, 14:00, 16:00, false" // 重複なし(離れている)
424
+ })
425
+ void 時間枠の重複判定が正しい(String start1, String end1, String start2, String end2, boolean expected) {
426
+ TimeSlot slot1 = createTimeSlot(start1, end1);
427
+ TimeSlot slot2 = createTimeSlot(start2, end2);
428
+
429
+ assertThat(slot1.overlaps(slot2)).isEqualTo(expected);
430
+ }
431
+ }
432
+ ```
433
+
434
+ **エンティティのテスト**
435
+ ```java
436
+ class ReservationTest {
437
+ @Test
438
+ void 予約作成時は確定状態になる() {
439
+ Reservation reservation = createValidReservation();
440
+
441
+ assertThat(reservation.getStatus()).isEqualTo(ReservationStatus.CONFIRMED);
442
+ assertThat(reservation.getId()).isNotNull();
443
+ assertThat(reservation.getCreatedAt()).isBeforeOrEqualTo(LocalDateTime.now());
444
+ }
445
+
446
+ @Test
447
+ void 変更可能な予約はタイトルを変更できる() {
448
+ Reservation reservation = createFutureReservation();
449
+ ReservationTitle newTitle = new ReservationTitle("新しいタイトル");
450
+
451
+ reservation.changeTitle(newTitle);
452
+
453
+ assertThat(reservation.getTitle()).isEqualTo(newTitle);
454
+ }
455
+
456
+ @Test
457
+ void 開始2時間前を過ぎた予約は変更できない() {
458
+ Reservation reservation = createNearFutureReservation(); // 1時間後開始
459
+
460
+ assertThatThrownBy(() -> reservation.changeTitle(new ReservationTitle("新タイトル")))
461
+ .isInstanceOf(IllegalStateException.class)
462
+ .hasMessageContaining("2時間前まで");
463
+ }
464
+
465
+ @Test
466
+ void キャンセルされた予約は再キャンセルできない() {
467
+ Reservation reservation = createValidReservation();
468
+ reservation.cancel(); // 一度キャンセル
469
+
470
+ assertThatThrownBy(reservation::cancel)
471
+ .isInstanceOf(IllegalStateException.class);
472
+ }
473
+ }
474
+ ```
475
+
476
+ **ドメインサービスのテスト**
477
+ ```java
478
+ @ExtendWith(MockitoExtension.class)
479
+ class ConflictCheckerTest {
480
+ @Mock
481
+ private ReservationRepository reservationRepository;
482
+
483
+ private ConflictChecker conflictChecker;
484
+
485
+ @BeforeEach
486
+ void setUp() {
487
+ conflictChecker = new ConflictChecker(reservationRepository);
488
+ }
489
+
490
+ @Test
491
+ void 重複する予約がない場合はfalseを返す() {
492
+ // Given
493
+ RoomId roomId = RoomId.generate();
494
+ TimeSlot newTimeSlot = createTimeSlot("10:00", "12:00");
495
+
496
+ when(reservationRepository.findActiveByRoomId(roomId))
497
+ .thenReturn(Collections.emptyList());
498
+
499
+ // When
500
+ boolean hasConflict = conflictChecker.hasConflict(roomId, newTimeSlot);
501
+
502
+ // Then
503
+ assertThat(hasConflict).isFalse();
504
+ }
505
+
506
+ @Test
507
+ void 完全に重複する場合はtrueを返す() {
508
+ // Given
509
+ RoomId roomId = RoomId.generate();
510
+ TimeSlot newTimeSlot = createTimeSlot("10:00", "12:00");
511
+ Reservation existingReservation = createReservationWithTimeSlot("10:00", "12:00");
512
+
513
+ when(reservationRepository.findActiveByRoomId(roomId))
514
+ .thenReturn(List.of(existingReservation));
515
+
516
+ // When
517
+ boolean hasConflict = conflictChecker.hasConflict(roomId, newTimeSlot);
518
+
519
+ // Then
520
+ assertThat(hasConflict).isTrue();
521
+ }
522
+
523
+ @Test
524
+ void 部分的に重複する場合はtrueを返す() {
525
+ // Given
526
+ RoomId roomId = RoomId.generate();
527
+ TimeSlot newTimeSlot = createTimeSlot("10:00", "12:00");
528
+ Reservation existingReservation = createReservationWithTimeSlot("11:00", "13:00");
529
+
530
+ when(reservationRepository.findActiveByRoomId(roomId))
531
+ .thenReturn(List.of(existingReservation));
532
+
533
+ // When
534
+ boolean hasConflict = conflictChecker.hasConflict(roomId, newTimeSlot);
535
+
536
+ // Then
537
+ assertThat(hasConflict).isTrue();
538
+ }
539
+ }
540
+ ```
541
+
542
+ #### レベル2:統合テスト(15%)
543
+
544
+ **対象**:アプリケーション層とインフラストラクチャ層の連携
545
+
546
+ **ユースケースの統合テスト**
547
+ ```java
548
+ @SpringBootTest
549
+ @Testcontainers
550
+ @Transactional
551
+ class CreateReservationUseCaseIntegrationTest {
552
+
553
+ @Container
554
+ static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15");
555
+
556
+ @Autowired
557
+ private CreateReservationUseCase createReservationUseCase;
558
+
559
+ @Autowired
560
+ private UserRepository userRepository;
561
+
562
+ @Autowired
563
+ private RoomRepository roomRepository;
564
+
565
+ @Autowired
566
+ private ReservationRepository reservationRepository;
567
+
568
+ @Test
569
+ void 有効な条件で予約を作成できる() {
570
+ // Given
571
+ User user = createAndSaveTestUser();
572
+ Room room = createAndSaveTestRoom();
573
+
574
+ CreateReservationCommand command = CreateReservationCommand.builder()
575
+ .userId(user.getId())
576
+ .roomId(room.getId())
577
+ .title("定例会議")
578
+ .purpose("週次定例会議")
579
+ .startTime(LocalDateTime.now().plusDays(1).withHour(10).withMinute(0))
580
+ .endTime(LocalDateTime.now().plusDays(1).withHour(12).withMinute(0))
581
+ .build();
582
+
583
+ // When
584
+ ReservationId reservationId = createReservationUseCase.execute(command);
585
+
586
+ // Then
587
+ assertThat(reservationId).isNotNull();
588
+
589
+ Optional<Reservation> savedReservation = reservationRepository.findById(reservationId);
590
+ assertThat(savedReservation).isPresent();
591
+ assertThat(savedReservation.get().getUserId()).isEqualTo(user.getId());
592
+ assertThat(savedReservation.get().getRoomId()).isEqualTo(room.getId());
593
+ assertThat(savedReservation.get().getStatus()).isEqualTo(ReservationStatus.CONFIRMED);
594
+ }
595
+
596
+ @Test
597
+ void 重複する時間帯の予約は失敗する() {
598
+ // Given
599
+ User user = createAndSaveTestUser();
600
+ Room room = createAndSaveTestRoom();
601
+
602
+ // 既存の予約を作成
603
+ LocalDateTime startTime = LocalDateTime.now().plusDays(1).withHour(10).withMinute(0);
604
+ LocalDateTime endTime = LocalDateTime.now().plusDays(1).withHour(12).withMinute(0);
605
+ createAndSaveReservation(user.getId(), room.getId(), startTime, endTime);
606
+
607
+ // 重複する新しい予約
608
+ CreateReservationCommand command = CreateReservationCommand.builder()
609
+ .userId(UserId.generate())
610
+ .roomId(room.getId())
611
+ .startTime(startTime.plusMinutes(30)) // 30分後開始(重複)
612
+ .endTime(endTime.plusMinutes(30))
613
+ .title("別の会議")
614
+ .purpose("別の用途")
615
+ .build();
616
+
617
+ // When & Then
618
+ assertThatThrownBy(() -> createReservationUseCase.execute(command))
619
+ .isInstanceOf(ReservationConflictException.class);
620
+ }
621
+
622
+ @Test
623
+ void 同時予約数制限を超える場合は失敗する() {
624
+ // Given
625
+ User user = createAndSaveTestUser();
626
+
627
+ // ユーザーに既に3件の予約を作成(上限まで)
628
+ createMaxReservationsForUser(user.getId());
629
+
630
+ CreateReservationCommand command = CreateReservationCommand.builder()
631
+ .userId(user.getId())
632
+ .roomId(RoomId.generate())
633
+ .startTime(LocalDateTime.now().plusDays(2).withHour(10).withMinute(0))
634
+ .endTime(LocalDateTime.now().plusDays(2).withHour(12).withMinute(0))
635
+ .title("4件目の予約")
636
+ .purpose("制限超過テスト")
637
+ .build();
638
+
639
+ // When & Then
640
+ assertThatThrownBy(() -> createReservationUseCase.execute(command))
641
+ .isInstanceOf(ReservationLimitExceededException.class);
642
+ }
643
+ }
644
+ ```
645
+
646
+ **リポジトリの統合テスト**
647
+ ```java
648
+ @DataJpaTest
649
+ @Testcontainers
650
+ class ReservationRepositoryIntegrationTest {
651
+
652
+ @Container
653
+ static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15");
654
+
655
+ @Autowired
656
+ private TestEntityManager entityManager;
657
+
658
+ @Autowired
659
+ private ReservationRepository reservationRepository;
660
+
661
+ @Test
662
+ void アクティブな予約のみ取得される() {
663
+ // Given
664
+ UserId userId = UserId.generate();
665
+ RoomId roomId = RoomId.generate();
666
+
667
+ Reservation activeReservation = createReservation(userId, roomId, ReservationStatus.CONFIRMED);
668
+ Reservation cancelledReservation = createReservation(userId, roomId, ReservationStatus.CANCELLED);
669
+ Reservation completedReservation = createReservation(userId, roomId, ReservationStatus.COMPLETED);
670
+
671
+ entityManager.persistAndFlush(activeReservation);
672
+ entityManager.persistAndFlush(cancelledReservation);
673
+ entityManager.persistAndFlush(completedReservation);
674
+
675
+ // When
676
+ List<Reservation> activeReservations = reservationRepository.findActiveByUserId(userId);
677
+
678
+ // Then
679
+ assertThat(activeReservations).hasSize(1);
680
+ assertThat(activeReservations.get(0).getId()).isEqualTo(activeReservation.getId());
681
+ }
682
+
683
+ @Test
684
+ void 指定日時範囲の予約が取得される() {
685
+ // Given
686
+ RoomId roomId = RoomId.generate();
687
+ LocalDate targetDate = LocalDate.of(2024, 1, 15);
688
+
689
+ Reservation targetDateReservation = createReservationOnDate(roomId, targetDate);
690
+ Reservation otherDateReservation = createReservationOnDate(roomId, targetDate.plusDays(1));
691
+
692
+ entityManager.persistAndFlush(targetDateReservation);
693
+ entityManager.persistAndFlush(otherDateReservation);
694
+
695
+ // When
696
+ List<Reservation> reservations = reservationRepository.findActiveByRoomIdAndDate(roomId, targetDate);
697
+
698
+ // Then
699
+ assertThat(reservations).hasSize(1);
700
+ assertThat(reservations.get(0).getId()).isEqualTo(targetDateReservation.getId());
701
+ }
702
+ }
703
+ ```
704
+
705
+ #### レベル3:E2Eテスト(5%)
706
+
707
+ **対象**:システム全体のユーザーシナリオ
708
+
709
+ **APIエンドポイントのE2Eテスト**
710
+ ```java
711
+ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
712
+ @Testcontainers
713
+ @AutoConfigureMockMvc
714
+ class ReservationApiE2ETest {
715
+
716
+ @Container
717
+ static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15");
718
+
719
+ @Autowired
720
+ private MockMvc mockMvc;
721
+
722
+ @Autowired
723
+ private ObjectMapper objectMapper;
724
+
725
+ @Test
726
+ @WithMockUser(roles = "MEMBER")
727
+ void 予約作成から確認までの一連の流れ() throws Exception {
728
+ // Given - テストデータを準備
729
+ setupTestData();
730
+
731
+ // When 1 - 利用可能な会議室を検索
732
+ MvcResult searchResult = mockMvc.perform(get("/api/rooms/search")
733
+ .param("date", "2024-01-15")
734
+ .param("startTime", "10:00")
735
+ .param("endTime", "12:00")
736
+ .param("minCapacity", "5"))
737
+ .andExpect(status().isOk())
738
+ .andReturn();
739
+
740
+ List<RoomSearchResult> rooms = objectMapper.readValue(
741
+ searchResult.getResponse().getContentAsString(),
742
+ new TypeReference<List<RoomSearchResult>>() {});
743
+ assertThat(rooms).isNotEmpty();
744
+
745
+ // When 2 - 会議室を予約
746
+ String roomId = rooms.get(0).getRoomId();
747
+ CreateReservationRequest request = CreateReservationRequest.builder()
748
+ .roomId(roomId)
749
+ .title("定例会議")
750
+ .purpose("週次定例会議")
751
+ .startTime(LocalDateTime.of(2024, 1, 15, 10, 0))
752
+ .endTime(LocalDateTime.of(2024, 1, 15, 12, 0))
753
+ .build();
754
+
755
+ MvcResult createResult = mockMvc.perform(post("/api/reservations")
756
+ .contentType(MediaType.APPLICATION_JSON)
757
+ .content(objectMapper.writeValueAsString(request)))
758
+ .andExpect(status().isCreated())
759
+ .andReturn();
760
+
761
+ ReservationResponse createdReservation = objectMapper.readValue(
762
+ createResult.getResponse().getContentAsString(),
763
+ ReservationResponse.class);
764
+
765
+ // When 3 - 作成した予約を確認
766
+ mockMvc.perform(get("/api/reservations/" + createdReservation.getReservationId()))
767
+ .andExpect(status().isOk())
768
+ .andExpect(jsonPath("$.title").value("定例会議"))
769
+ .andExpect(jsonPath("$.status").value("CONFIRMED"))
770
+ .andExpect(jsonPath("$.roomId").value(roomId));
771
+
772
+ // When 4 - ユーザーの予約一覧を確認
773
+ mockMvc.perform(get("/api/reservations/my"))
774
+ .andExpected(status().isOk())
775
+ .andExpect(jsonPath("$").isArray())
776
+ .andExpect(jsonPath("$[0].reservationId").value(createdReservation.getReservationId()));
777
+ }
778
+
779
+ @Test
780
+ @WithMockUser(roles = "MEMBER")
781
+ void 予約キャンセルの一連の流れ() throws Exception {
782
+ // Given - 事前に予約を作成
783
+ String reservationId = createTestReservation();
784
+
785
+ // When 1 - 予約をキャンセル
786
+ mockMvc.perform(delete("/api/reservations/" + reservationId))
787
+ .andExpected(status().isNoContent());
788
+
789
+ // Then - キャンセル状態になっていることを確認
790
+ mockMvc.perform(get("/api/reservations/" + reservationId))
791
+ .andExpected(status().isOk())
792
+ .andExpect(jsonPath("$.status").value("CANCELLED"));
793
+ }
794
+
795
+ @Test
796
+ @WithMockUser(roles = "MEMBER")
797
+ void 重複予約のエラーハンドリング() throws Exception {
798
+ // Given - 既存の予約を作成
799
+ createTestReservationAt(LocalDateTime.of(2024, 1, 15, 10, 0));
800
+
801
+ // When - 重複する時間で予約を試行
802
+ CreateReservationRequest request = CreateReservationRequest.builder()
803
+ .roomId("test-room-id")
804
+ .title("重複する会議")
805
+ .purpose("重複テスト")
806
+ .startTime(LocalDateTime.of(2024, 1, 15, 11, 0)) // 1時間後開始(重複)
807
+ .endTime(LocalDateTime.of(2024, 1, 15, 13, 0))
808
+ .build();
809
+
810
+ // Then - 適切なエラーレスポンスが返される
811
+ mockMvc.perform(post("/api/reservations")
812
+ .contentType(MediaType.APPLICATION_JSON)
813
+ .content(objectMapper.writeValueAsString(request)))
814
+ .andExpect(status().isConflict())
815
+ .andExpect(jsonPath("$.error").value("RESERVATION_CONFLICT"))
816
+ .andExpect(jsonPath("$.message").value("指定時間は既に予約されています"));
817
+ }
818
+ }
819
+ ```
820
+
821
+ ### テスト実行戦略
822
+
823
+ #### 継続的インテグレーション(CI)
824
+
825
+ ```plantuml
826
+ @startuml
827
+ start
828
+
829
+ :コミット;
830
+ :ユニットテスト実行;
831
+
832
+ if (ユニットテスト成功?) then (yes)
833
+ :統合テスト実行;
834
+ if (統合テスト成功?) then (yes)
835
+ :E2Eテスト実行;
836
+ if (E2Eテスト成功?) then (yes)
837
+ :デプロイ;
838
+ stop
839
+ else (no)
840
+ :E2Eテスト失敗通知;
841
+ stop
842
+ endif
843
+ else (no)
844
+ :統合テスト失敗通知;
845
+ stop
846
+ endif
847
+ else (no)
848
+ :ユニットテスト失敗通知;
849
+ stop
850
+ endif
851
+
852
+ @enduml
853
+ ```
854
+
855
+ #### テスト実行時間の目標
856
+
857
+ - **ユニットテスト**: 30秒以内
858
+ - **統合テスト**: 2分以内
859
+ - **E2Eテスト**: 10分以内
860
+ - **全テスト**: 15分以内
861
+
862
+ #### 並列実行戦略
863
+
864
+ ```yml
865
+ # .github/workflows/test.yml
866
+ name: Test
867
+ on: [push, pull_request]
868
+
869
+ jobs:
870
+ unit-tests:
871
+ runs-on: ubuntu-latest
872
+ steps:
873
+ - uses: actions/checkout@v3
874
+ - uses: actions/setup-java@v3
875
+ with:
876
+ java-version: '21'
877
+ - run: ./mvnw test -Dtest="**/*Test" # ユニットテストのみ
878
+
879
+ integration-tests:
880
+ runs-on: ubuntu-latest
881
+ needs: unit-tests
882
+ steps:
883
+ - uses: actions/checkout@v3
884
+ - uses: actions/setup-java@v3
885
+ with:
886
+ java-version: '21'
887
+ - run: ./mvnw test -Dtest="**/*IntegrationTest"
888
+
889
+ e2e-tests:
890
+ runs-on: ubuntu-latest
891
+ needs: integration-tests
892
+ steps:
893
+ - uses: actions/checkout@v3
894
+ - uses: actions/setup-java@v3
895
+ with:
896
+ java-version: '21'
897
+ - run: ./mvnw test -Dtest="**/*E2ETest"
898
+ ```
899
+
900
+ ## テストデータ管理
901
+
902
+ ### テストデータ戦略
903
+
904
+ #### テストフィクスチャ
905
+
906
+ **Object Mother パターン**
907
+ ```java
908
+ public class ReservationFixture {
909
+
910
+ public static Reservation validReservation() {
911
+ return Reservation.create(
912
+ UserFixture.defaultUserId(),
913
+ RoomFixture.defaultRoomId(),
914
+ new ReservationTitle("定例会議"),
915
+ new Purpose("週次定例会議"),
916
+ TimeSlotFixture.tomorrowMorning()
917
+ );
918
+ }
919
+
920
+ public static Reservation reservationStartingAt(LocalDateTime startTime) {
921
+ return Reservation.create(
922
+ UserFixture.defaultUserId(),
923
+ RoomFixture.defaultRoomId(),
924
+ new ReservationTitle("会議"),
925
+ new Purpose("テスト用"),
926
+ new TimeSlot(startTime, startTime.plusHours(2))
927
+ );
928
+ }
929
+
930
+ public static Reservation pastReservation() {
931
+ return Reservation.create(
932
+ UserFixture.defaultUserId(),
933
+ RoomFixture.defaultRoomId(),
934
+ new ReservationTitle("過去の会議"),
935
+ new Purpose("過去のテスト"),
936
+ TimeSlotFixture.yesterday()
937
+ );
938
+ }
939
+ }
940
+
941
+ public class TimeSlotFixture {
942
+
943
+ public static TimeSlot tomorrowMorning() {
944
+ LocalDateTime start = LocalDateTime.now().plusDays(1).withHour(10).withMinute(0);
945
+ return new TimeSlot(start, start.plusHours(2));
946
+ }
947
+
948
+ public static TimeSlot yesterday() {
949
+ LocalDateTime start = LocalDateTime.now().minusDays(1).withHour(10).withMinute(0);
950
+ return new TimeSlot(start, start.plusHours(2));
951
+ }
952
+
953
+ public static TimeSlot nextWeek() {
954
+ LocalDateTime start = LocalDateTime.now().plusWeeks(1).withHour(14).withMinute(0);
955
+ return new TimeSlot(start, start.plusHours(3));
956
+ }
957
+ }
958
+ ```
959
+
960
+ #### テストビルダーパターン
961
+
962
+ ```java
963
+ public class ReservationTestDataBuilder {
964
+ private UserId userId = UserFixture.defaultUserId();
965
+ private RoomId roomId = RoomFixture.defaultRoomId();
966
+ private ReservationTitle title = new ReservationTitle("テスト会議");
967
+ private Purpose purpose = new Purpose("テスト用途");
968
+ private TimeSlot timeSlot = TimeSlotFixture.tomorrowMorning();
969
+
970
+ public ReservationTestDataBuilder withUserId(UserId userId) {
971
+ this.userId = userId;
972
+ return this;
973
+ }
974
+
975
+ public ReservationTestDataBuilder withRoomId(RoomId roomId) {
976
+ this.roomId = roomId;
977
+ return this;
978
+ }
979
+
980
+ public ReservationTestDataBuilder withTitle(String title) {
981
+ this.title = new ReservationTitle(title);
982
+ return this;
983
+ }
984
+
985
+ public ReservationTestDataBuilder withTimeSlot(TimeSlot timeSlot) {
986
+ this.timeSlot = timeSlot;
987
+ return this;
988
+ }
989
+
990
+ public ReservationTestDataBuilder startingAt(LocalDateTime startTime) {
991
+ this.timeSlot = new TimeSlot(startTime, startTime.plusHours(2));
992
+ return this;
993
+ }
994
+
995
+ public Reservation build() {
996
+ return Reservation.create(userId, roomId, title, purpose, timeSlot);
997
+ }
998
+ }
999
+
1000
+ // 使用例
1001
+ @Test
1002
+ void 特定の条件でのテスト() {
1003
+ Reservation reservation = new ReservationTestDataBuilder()
1004
+ .withTitle("重要な会議")
1005
+ .startingAt(LocalDateTime.of(2024, 1, 15, 14, 0))
1006
+ .build();
1007
+
1008
+ // テスト実行...
1009
+ }
1010
+ ```
1011
+
1012
+ ### データベーステストでのデータ管理
1013
+
1014
+ #### Testcontainers によるデータベース環境
1015
+
1016
+ ```java
1017
+ @SpringBootTest
1018
+ @Testcontainers
1019
+ public abstract class DatabaseTestBase {
1020
+
1021
+ @Container
1022
+ static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15")
1023
+ .withDatabaseName("testdb")
1024
+ .withUsername("test")
1025
+ .withPassword("test")
1026
+ .withInitScript("test-schema.sql");
1027
+
1028
+ @DynamicPropertySource
1029
+ static void configureProperties(DynamicPropertyRegistry registry) {
1030
+ registry.add("spring.datasource.url", postgres::getJdbcUrl);
1031
+ registry.add("spring.datasource.username", postgres::getUsername);
1032
+ registry.add("spring.datasource.password", postgres::getPassword);
1033
+ }
1034
+ }
1035
+ ```
1036
+
1037
+ #### トランザクショナルテスト
1038
+
1039
+ ```java
1040
+ @SpringBootTest
1041
+ @Transactional
1042
+ @Rollback
1043
+ class TransactionalIntegrationTest extends DatabaseTestBase {
1044
+
1045
+ @Test
1046
+ void データ変更テスト() {
1047
+ // テスト内でのデータ変更は自動でロールバックされる
1048
+ User user = new User(/* ... */);
1049
+ userRepository.save(user);
1050
+
1051
+ // テスト実行...
1052
+ }
1053
+ }
1054
+ ```
1055
+
1056
+ ## モックとスタブの活用
1057
+
1058
+ ### モッキング戦略
1059
+
1060
+ #### 依存関係の分離
1061
+
1062
+ ```java
1063
+ @ExtendWith(MockitoExtension.class)
1064
+ class CreateReservationUseCaseTest {
1065
+
1066
+ @Mock private UserRepository userRepository;
1067
+ @Mock private RoomRepository roomRepository;
1068
+ @Mock private ReservationRepository reservationRepository;
1069
+ @Mock private ConflictChecker conflictChecker;
1070
+ @Mock private ReservationLimitChecker limitChecker;
1071
+
1072
+ @InjectMocks
1073
+ private CreateReservationService useCase;
1074
+
1075
+ @Test
1076
+ void 正常な予約作成() {
1077
+ // Given
1078
+ User user = UserFixture.activeMember();
1079
+ Room room = RoomFixture.availableRoom();
1080
+
1081
+ when(userRepository.findById(any(UserId.class))).thenReturn(Optional.of(user));
1082
+ when(roomRepository.findById(any(RoomId.class))).thenReturn(Optional.of(room));
1083
+ when(conflictChecker.hasConflict(any(), any())).thenReturn(false);
1084
+ when(limitChecker.canUserMakeReservation(any())).thenReturn(true);
1085
+
1086
+ // When
1087
+ ReservationId result = useCase.execute(createValidCommand());
1088
+
1089
+ // Then
1090
+ assertThat(result).isNotNull();
1091
+ verify(reservationRepository).save(any(Reservation.class));
1092
+ }
1093
+ }
1094
+ ```
1095
+
1096
+ #### 外部システムのモック
1097
+
1098
+ ```java
1099
+ @TestConfiguration
1100
+ public class TestExternalSystemConfig {
1101
+
1102
+ @Bean
1103
+ @Primary
1104
+ public EmailService mockEmailService() {
1105
+ return Mockito.mock(EmailService.class);
1106
+ }
1107
+
1108
+ @Bean
1109
+ @Primary
1110
+ public NotificationService mockNotificationService() {
1111
+ return Mockito.mock(NotificationService.class);
1112
+ }
1113
+ }
1114
+ ```
1115
+
1116
+ ## 性能テスト
1117
+
1118
+ ### 性能テスト戦略
1119
+
1120
+ #### JMeter による負荷テスト
1121
+
1122
+ ```xml
1123
+ <?xml version="1.0" encoding="UTF-8"?>
1124
+ <jmeterTestPlan version="1.2">
1125
+ <TestPlan testname="会議室予約システム負荷テスト">
1126
+ <ThreadGroup testname="予約作成負荷テスト">
1127
+ <stringProp name="ThreadGroup.num_threads">100</stringProp>
1128
+ <stringProp name="ThreadGroup.ramp_time">60</stringProp>
1129
+ <stringProp name="ThreadGroup.duration">300</stringProp>
1130
+
1131
+ <HTTPSamplerProxy testname="予約作成API">
1132
+ <stringProp name="HTTPSampler.path">/api/reservations</stringProp>
1133
+ <stringProp name="HTTPSampler.method">POST</stringProp>
1134
+ <elementProp name="HTTPsampler.Arguments" elementType="Arguments">
1135
+ <collectionProp>
1136
+ <elementProp name="" elementType="HTTPArgument">
1137
+ <stringProp name="Argument.value">{
1138
+ "roomId": "${roomId}",
1139
+ "title": "負荷テスト予約",
1140
+ "startTime": "${startTime}",
1141
+ "endTime": "${endTime}"
1142
+ }</stringProp>
1143
+ </elementProp>
1144
+ </collectionProp>
1145
+ </elementProp>
1146
+ </HTTPSamplerProxy>
1147
+ </ThreadGroup>
1148
+ </TestPlan>
1149
+ </jmeterTestPlan>
1150
+ ```
1151
+
1152
+ #### JUnit による性能テスト
1153
+
1154
+ ```java
1155
+ @Test
1156
+ @Timeout(value = 100, unit = TimeUnit.MILLISECONDS)
1157
+ void 重複チェックは100ms以内に完了する() {
1158
+ // Given - 大量の予約データを準備
1159
+ RoomId roomId = RoomId.generate();
1160
+ setupLargeReservationDataset(roomId, 1000);
1161
+
1162
+ // When
1163
+ TimeSlot newTimeSlot = TimeSlotFixture.tomorrowMorning();
1164
+ boolean hasConflict = conflictChecker.hasConflict(roomId, newTimeSlot);
1165
+
1166
+ // Then - タイムアウトアノテーションにより100ms以内に完了することを検証
1167
+ assertThat(hasConflict).isFalse();
1168
+ }
1169
+
1170
+ @ParameterizedTest
1171
+ @ValueSource(ints = {10, 50, 100, 500, 1000})
1172
+ void 予約数に関係なく検索性能が一定(int reservationCount) {
1173
+ // Given
1174
+ RoomId roomId = RoomId.generate();
1175
+ setupReservationDataset(roomId, reservationCount);
1176
+
1177
+ // When - 実行時間を計測
1178
+ long startTime = System.nanoTime();
1179
+ List<Reservation> results = reservationRepository.findActiveByRoomId(roomId);
1180
+ long endTime = System.nanoTime();
1181
+
1182
+ // Then - 実行時間が予約数に比例して増加しないことを検証
1183
+ long executionTimeMs = (endTime - startTime) / 1_000_000;
1184
+ assertThat(executionTimeMs).isLessThan(50); // 50ms以内
1185
+ assertThat(results).hasSize(reservationCount);
1186
+ }
1187
+ ```
1188
+
1189
+ ## カバレッジ戦略
1190
+
1191
+ ### コードカバレッジ目標
1192
+
1193
+ - **ドメイン層**: 90%以上
1194
+ - **アプリケーション層**: 85%以上
1195
+ - **インフラストラクチャ層**: 70%以上
1196
+ - **全体**: 80%以上
1197
+
1198
+ ### JaCoCo設定
1199
+
1200
+ ```xml
1201
+ <plugin>
1202
+ <groupId>org.jacoco</groupId>
1203
+ <artifactId>jacoco-maven-plugin</artifactId>
1204
+ <version>0.8.8</version>
1205
+ <executions>
1206
+ <execution>
1207
+ <goals>
1208
+ <goal>prepare-agent</goal>
1209
+ </goals>
1210
+ </execution>
1211
+ <execution>
1212
+ <id>report</id>
1213
+ <phase>test</phase>
1214
+ <goals>
1215
+ <goal>report</goal>
1216
+ </goals>
1217
+ </execution>
1218
+ <execution>
1219
+ <id>check</id>
1220
+ <goals>
1221
+ <goal>check</goal>
1222
+ </goals>
1223
+ <configuration>
1224
+ <rules>
1225
+ <rule>
1226
+ <element>PACKAGE</element>
1227
+ <limits>
1228
+ <limit>
1229
+ <counter>LINE</counter>
1230
+ <value>COVEREDRATIO</value>
1231
+ <minimum>0.80</minimum>
1232
+ </limit>
1233
+ </limits>
1234
+ </rule>
1235
+ <rule>
1236
+ <element>CLASS</element>
1237
+ <includes>
1238
+ <include>com.example.domain.*</include>
1239
+ </includes>
1240
+ <limits>
1241
+ <limit>
1242
+ <counter>LINE</counter>
1243
+ <value>COVEREDRATIO</value>
1244
+ <minimum>0.90</minimum>
1245
+ </limit>
1246
+ </limits>
1247
+ </rule>
1248
+ </rules>
1249
+ </configuration>
1250
+ </execution>
1251
+ </executions>
1252
+ </plugin>
1253
+ ```
1254
+
1255
+ ### 変異テスト(Mutation Testing)
1256
+
1257
+ ```xml
1258
+ <plugin>
1259
+ <groupId>org.pitest</groupId>
1260
+ <artifactId>pitest-maven</artifactId>
1261
+ <version>1.9.0</version>
1262
+ <configuration>
1263
+ <targetClasses>
1264
+ <param>com.example.domain.*</param>
1265
+ </targetClasses>
1266
+ <targetTests>
1267
+ <param>com.example.domain.*Test</param>
1268
+ </targetTests>
1269
+ <mutators>
1270
+ <mutator>STRONGER</mutator>
1271
+ </mutators>
1272
+ <mutationThreshold>75</mutationThreshold>
1273
+ </configuration>
1274
+ </plugin>
1275
+ ```
1276
+
1277
+ ## まとめ
1278
+
1279
+ ### テスト戦略の要点
1280
+
1281
+ 1. **アーキテクチャに応じた適切な戦略選択**
1282
+ - ドメインモデル → ピラミッド形テスト
1283
+ - アクティブレコード → ダイヤモンド形テスト
1284
+ - トランザクションスクリプト → 逆ピラミッド形テスト
1285
+
1286
+ 2. **TDD による品質向上**
1287
+ - Red-Green-Refactor サイクル
1288
+ - テストファーストによる設計改善
1289
+ - 継続的なリファクタリング
1290
+
1291
+ 3. **効率的なテスト実行**
1292
+ - 高速なフィードバックループ
1293
+ - 並列実行による時間短縮
1294
+ - CI/CD パイプラインとの統合
1295
+
1296
+ 4. **適切なテスト範囲**
1297
+ - ドメイン層への重点的な投資
1298
+ - 外部依存の適切な分離
1299
+ - 実用的なカバレッジ目標
1300
+
1301
+ ### 継続的改善
1302
+
1303
+ テスト戦略は継続的に見直し、改善していく。以下の指標でテストの効果を測定:
1304
+
1305
+ - **欠陥検出率**: テストで発見できる欠陥の割合
1306
+ - **回帰テスト効率**: リグレッションの早期発見
1307
+ - **開発速度**: テストによる開発スピードへの影響
1308
+ - **保守性**: テストコード自体の保守しやすさ
1309
+
1310
+ 変更を楽に安全にできて役に立つソフトウェアを実現するため、テストは品質保証の手段であると同時に、設計改善のツールとして活用する。