@@ -11,114 +11,136 @@ import XCTest
1111final class SelectiveTestingWorksapceTests : XCTestCase {
1212 let testTool = IntegrationTestTool ( )
1313
14- override func setUp( ) async throws {
15- try await super. setUp ( )
16-
17- try testTool. setUp ( )
18- }
19-
20- override func tearDown( ) async throws {
21- try await super. tearDown ( )
22-
23- try testTool. tearDown ( )
24- }
25-
2614 func testProjectLoading_empty( ) async throws {
27- // given
28- let tool = try testTool. createSUT ( )
29- // when
30- let result = try await tool. run ( )
31- // then
32- XCTAssertEqual ( result, Set ( ) )
15+ try await testTool. withTestTool {
16+ // given
17+ let tool = try testTool. createSUT ( )
18+ // when
19+ let result = try await tool. run ( )
20+ // then
21+ XCTAssertEqual ( result, Set ( ) )
22+ }
3323 }
3424
3525 func testProjectLoading_changeLibrary( ) async throws {
36- // given
37- let tool = try testTool. createSUT ( )
38- // when
39- try testTool. changeFile ( at: testTool. projectPath + " ExampleLibrary/ExampleLibrary/ExampleLibrary.swift " )
40-
41- // then
42- let result = try await tool. run ( )
43- XCTAssertEqual ( result, Set ( [ testTool. mainProjectMainTarget,
44- testTool. mainProjectTests,
45- testTool. mainProjectUITests,
46- testTool. exampleLibrary,
47- testTool. exampleLibraryTests] ) )
26+ try await testTool. withTestTool {
27+ // given
28+ let tool = try testTool. createSUT ( )
29+ // when
30+ try testTool. changeFile ( at: testTool. projectPath + " ExampleLibrary/ExampleLibrary/ExampleLibrary.swift " )
31+
32+ // then
33+ let result = try await tool. run ( )
34+ XCTAssertEqual ( result, Set ( [ testTool. mainProjectMainTarget,
35+ testTool. mainProjectTests,
36+ testTool. mainProjectUITests,
37+ testTool. exampleLibrary,
38+ testTool. exampleLibraryTests] ) )
39+ }
4840 }
4941
5042 func testProjectLoading_changeAsset( ) async throws {
51- // given
52- let tool = try testTool. createSUT ( )
53- // when
54- try testTool. changeFile ( at: testTool. projectPath + " ExampleProject/Assets.xcassets/Contents.json " )
55-
56- // then
57- let result = try await tool. run ( )
58- XCTAssertEqual ( result, Set ( [ testTool. mainProjectMainTarget,
59- testTool. mainProjectTests,
60- testTool. mainProjectUITests] ) )
43+ try await testTool. withTestTool {
44+ // given
45+ let tool = try testTool. createSUT ( )
46+ // when
47+ try testTool. changeFile ( at: testTool. projectPath + " ExampleProject/Assets.xcassets/Contents.json " )
48+
49+ // then
50+ let result = try await tool. run ( )
51+ XCTAssertEqual ( result, Set ( [ testTool. mainProjectMainTarget,
52+ testTool. mainProjectTests,
53+ testTool. mainProjectUITests] ) )
54+ }
6155 }
6256
6357 func testProjectLoading_testPlanChange( ) async throws {
64- // given
65- let tool = try testTool. createSUT ( )
66- // when
67- try testTool. changeFile ( at: testTool. projectPath + " ExampleProject.xctestplan " )
68-
69- // then
70- let result = try await tool. run ( )
71- XCTAssertEqual ( result, Set ( ) )
58+ try await testTool. withTestTool {
59+ // given
60+ let tool = try testTool. createSUT ( )
61+ // when
62+ try testTool. changeFile ( at: testTool. projectPath + " ExampleProject.xctestplan " )
63+
64+ // then
65+ let result = try await tool. run ( )
66+ XCTAssertEqual ( result, Set ( ) )
67+ }
7268 }
7369
7470 func testProjectLoading_testWorkspaceFileChange( ) async throws {
75- // given
76- let tool = try testTool. createSUT ( )
77- // when
78- try testTool. changeFile ( at: testTool. projectPath + " ExampleWorkspace.xcworkspace/contents.xcworkspacedata " )
79- // then
80- let result = try await tool. run ( )
81- XCTAssertEqual ( result, Set ( [
82- testTool. mainProjectMainTarget,
83- testTool. mainProjectTests,
84- testTool. mainProjectUITests,
85- testTool. mainProjectLibrary,
86- testTool. mainProjectLibraryTests,
87- testTool. exampleLibraryTests,
88- testTool. exampleLibrary,
89- testTool. exampleLibraryInGroup,
90- ] ) )
71+ try await testTool. withTestTool {
72+ // given
73+ let tool = try testTool. createSUT ( )
74+ // when
75+ try testTool. changeFile ( at: testTool. projectPath + " ExampleWorkspace.xcworkspace/contents.xcworkspacedata " )
76+ // then
77+ let result = try await tool. run ( )
78+ XCTAssertEqual ( result, Set ( [
79+ testTool. mainProjectMainTarget,
80+ testTool. mainProjectTests,
81+ testTool. mainProjectUITests,
82+ testTool. mainProjectLibrary,
83+ testTool. mainProjectLibraryTests,
84+ testTool. exampleLibraryTests,
85+ testTool. exampleLibrary,
86+ testTool. exampleLibraryInGroup,
87+ ] ) )
88+ }
9189 }
9290
9391 func testProjectLoading_testProjectFileChange( ) async throws {
94- // given
95- let tool = try testTool. createSUT ( )
96- // when
97- try testTool. changeFile ( at: testTool. projectPath + " ExampleProject.xcodeproj/project.pbxproj " )
98-
99- // then
100- let result = try await tool. run ( )
101- XCTAssertEqual ( result, Set ( [
102- testTool. mainProjectMainTarget,
103- testTool. mainProjectTests,
104- testTool. mainProjectUITests,
105- testTool. mainProjectLibrary,
106- testTool. mainProjectLibraryTests,
107- ] ) )
92+ try await testTool. withTestTool {
93+ // given
94+ let tool = try testTool. createSUT ( )
95+ // when
96+ try testTool. changeFile ( at: testTool. projectPath + " ExampleProject.xcodeproj/project.pbxproj " )
97+
98+ // then
99+ let result = try await tool. run ( )
100+ XCTAssertEqual ( result, Set ( [
101+ testTool. mainProjectMainTarget,
102+ testTool. mainProjectTests,
103+ testTool. mainProjectUITests,
104+ testTool. mainProjectLibrary,
105+ testTool. mainProjectLibraryTests,
106+ ] ) )
107+ }
108108 }
109109
110110 func testInferTestPlan( ) async throws {
111- // given
112- let tool = try testTool. createSUT ( config: nil ,
113- testPlan: nil )
114- // when
115- try testTool. changeFile ( at: testTool. projectPath + " ExampleLibrary/ExampleLibrary/ExampleLibrary.swift " )
116-
117- // then
118- let _ = try await tool. run ( )
119- try testTool. validateTestPlan ( testPlanPath: testTool. projectPath + " ExampleProject.xctestplan " ,
120- expected: Set ( [ testTool. mainProjectTests,
121- testTool. mainProjectUITests,
122- testTool. exampleLibraryTests] ) )
111+ try await testTool. withTestTool {
112+ // given
113+ let tool = try testTool. createSUT ( config: nil ,
114+ testPlan: nil )
115+ // when
116+ try testTool. changeFile ( at: testTool. projectPath + " ExampleLibrary/ExampleLibrary/ExampleLibrary.swift " )
117+
118+ // then
119+ let _ = try await tool. run ( )
120+ try testTool. validateTestPlan ( testPlanPath: testTool. projectPath + " ExampleProject.xctestplan " ,
121+ expected: Set ( [ testTool. mainProjectTests,
122+ testTool. mainProjectUITests,
123+ testTool. exampleLibraryTests] ) )
124+ }
125+ }
126+
127+ func testInferTestPlanInSubfolder( ) async throws {
128+ try await testTool. withTestTool ( subfolder: true ) {
129+ // given
130+ let tool = try testTool. createSUT (
131+ config: nil ,
132+ basePath: testTool. projectPath + " Subfolder " ,
133+ testPlan: nil )
134+
135+ // when
136+ try testTool. changeFile ( at: testTool. projectPath + " Subfolder/ExampleLibrary/ExampleLibrary/ExampleLibrary.swift " )
137+
138+ // then
139+ let _ = try await tool. run ( )
140+ try testTool. validateTestPlan ( testPlanPath: testTool. projectPath + " Subfolder/ExampleProject.xctestplan " ,
141+ expected: Set ( [ testTool. mainProjectTests,
142+ testTool. mainProjectUITests,
143+ testTool. exampleLibraryTests] ) )
144+ }
123145 }
124146}
0 commit comments