Skip to content

Commit 0039d4b

Browse files
authored
Merge pull request #12 from Kyome22/swift-testing
Migrate to Swift Testing
2 parents 5045eed + c0a05ba commit 0039d4b

6 files changed

Lines changed: 110 additions & 92 deletions

File tree

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import DataLayer
22
import os
3-
import XCTest
3+
import Testing
44

55
@testable import Domain
66

7-
final class LogServiceTests: XCTestCase {
8-
func test_bootstrapは一度しか実行されない() async {
7+
struct LogServiceTests {
8+
@Test
9+
func bootstrapは一度しか実行されない() async {
910
let count = OSAllocatedUnfairLock(initialState: 0)
1011
let loggingSystemClient = testDependency(of: LoggingSystemClient.self) {
1112
$0.bootstrap = { _ in count.withLock { $0 += 1 } }
@@ -14,6 +15,6 @@ final class LogServiceTests: XCTestCase {
1415
await sut.bootstrap()
1516
await sut.bootstrap()
1617
let actual = count.withLock(\.self)
17-
XCTAssertEqual(actual, 1)
18+
#expect(actual == 1)
1819
}
1920
}

ShiftWindowPackages/Tests/DomainTests/ServiceTests/ShiftServiceTests.swift

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import AppKit
12
import DataLayer
23
import os
3-
import XCTest
4+
import Testing
45

56
@testable import Domain
67

7-
final class ShiftServiceTests: XCTestCase {
8-
func test_getValidFrame_MainScreenが取得不能_nilが返される() async {
8+
struct ShiftServiceTests {
9+
@Test
10+
func getValidFrame_MainScreenが取得不能_nilが返される() async {
911
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
1012
let actual = await sut.getValidFrame()
11-
XCTAssertNil(actual)
13+
#expect(actual == nil)
1214
}
1315

14-
func test_getValidFrame_MainScreenが取得可能_Dockが下部に存在_有効領域が返される() async {
16+
@Test
17+
func getValidFrame_MainScreenが取得可能_Dockが下部に存在_有効領域が返される() async {
1518
let nsScreenClient = testDependency(of: NSScreenClient.self) {
1619
$0.mainScreen = { NSScreenMock(x: 0, y: 0, width: 100, height: 95) }
1720
}
@@ -23,10 +26,11 @@ final class ShiftServiceTests: XCTestCase {
2326
}
2427
let sut = ShiftService(cgDirectDisplayClient, .testValue, nsAppClient, nsScreenClient, .testValue)
2528
let actual = await sut.getValidFrame()
26-
XCTAssertEqual(actual, CGRect(x: 0, y: 5, width: 100, height: 95))
29+
#expect(actual == CGRect(x: 0, y: 5, width: 100, height: 95))
2730
}
2831

29-
func test_getValidFrame_MainScreenが取得可能_Dockが右側に存在_有効領域が返される() async {
32+
@Test
33+
func getValidFrame_MainScreenが取得可能_Dockが右側に存在_有効領域が返される() async {
3034
let nsScreenClient = testDependency(of: NSScreenClient.self) {
3135
$0.mainScreen = { NSScreenMock(x: 0, y: 0, width: 95, height: 95) }
3236
}
@@ -38,10 +42,11 @@ final class ShiftServiceTests: XCTestCase {
3842
}
3943
let sut = ShiftService(cgDirectDisplayClient, .testValue, nsAppClient, nsScreenClient, .testValue)
4044
let actual = await sut.getValidFrame()
41-
XCTAssertEqual(actual, CGRect(x: 0, y: 5, width: 94, height: 95))
45+
#expect(actual == CGRect(x: 0, y: 5, width: 94, height: 95))
4246
}
4347

44-
func test_getValidFrame_MainScreenが取得可能_Dockが左側に存在_有効領域が返される() async {
48+
@Test
49+
func getValidFrame_MainScreenが取得可能_Dockが左側に存在_有効領域が返される() async {
4550
let nsScreenClient = testDependency(of: NSScreenClient.self) {
4651
$0.mainScreen = { NSScreenMock(x: 5, y: 0, width: 95, height: 95) }
4752
}
@@ -53,73 +58,84 @@ final class ShiftServiceTests: XCTestCase {
5358
}
5459
let sut = ShiftService(cgDirectDisplayClient, .testValue, nsAppClient, nsScreenClient, .testValue)
5560
let actual = await sut.getValidFrame()
56-
XCTAssertEqual(actual, CGRect(x: 6, y: 5, width: 94, height: 95))
61+
#expect(actual == CGRect(x: 6, y: 5, width: 94, height: 95))
5762
}
5863

59-
func test_makeNewFrame_幅が負_nilが返される() async {
64+
@Test
65+
func makeNewFrame_幅が負_nilが返される() async {
6066
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
6167
let actual = await sut.makeNewFrame(shiftType: .maximize, validFrame: CGRect(x: 0, y: 0, width: -1, height: 0))
62-
XCTAssertNil(actual)
68+
#expect(actual == nil)
6369
}
6470

65-
func test_makeNewFrame_高さが負_nilが返される() async {
71+
@Test
72+
func makeNewFrame_高さが負_nilが返される() async {
6673
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
6774
let actual = await sut.makeNewFrame(shiftType: .maximize, validFrame: CGRect(x: 0, y: 0, width: 0, height: -1))
68-
XCTAssertNil(actual)
75+
#expect(actual == nil)
6976
}
7077

71-
func test_makeNewFrame_上側1/2_領域が返される() async {
78+
@Test
79+
func makeNewFrame_上側1/2_領域が返される() async {
7280
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
7381
let actual = await sut.makeNewFrame(shiftType: .topHalf, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
74-
XCTAssertEqual(actual, CGRect(x: 0, y: 0, width: 100, height: 50))
82+
#expect(actual == CGRect(x: 0, y: 0, width: 100, height: 50))
7583
}
7684

77-
func test_makeNewFrame_下側1/2_領域が返される() async {
85+
@Test
86+
func makeNewFrame_下側1/2_領域が返される() async {
7887
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
7988
let actual = await sut.makeNewFrame(shiftType: .bottomHalf, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
80-
XCTAssertEqual(actual, CGRect(x: 0, y: 50, width: 100, height: 50))
89+
#expect(actual == CGRect(x: 0, y: 50, width: 100, height: 50))
8190
}
8291

83-
func test_makeNewFrame_左側1/2_領域が返される() async {
92+
@Test
93+
func makeNewFrame_左側1/2_領域が返される() async {
8494
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
8595
let actual = await sut.makeNewFrame(shiftType: .leftHalf, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
86-
XCTAssertEqual(actual, CGRect(x: 0, y: 0, width: 50, height: 100))
96+
#expect(actual == CGRect(x: 0, y: 0, width: 50, height: 100))
8797
}
8898

89-
func test_makeNewFrame_右側1/2_領域が返される() async {
99+
@Test
100+
func makeNewFrame_右側1/2_領域が返される() async {
90101
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
91102
let actual = await sut.makeNewFrame(shiftType: .rightHalf, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
92-
XCTAssertEqual(actual, CGRect(x: 50, y: 0, width: 50, height: 100))
103+
#expect(actual == CGRect(x: 50, y: 0, width: 50, height: 100))
93104
}
94105

95-
func test_makeNewFrame_左側1/3_領域が返される() async {
106+
@Test
107+
func makeNewFrame_左側1/3_領域が返される() async {
96108
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
97109
let actual = await sut.makeNewFrame(shiftType: .leftThird, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
98-
XCTAssertEqual(actual, CGRect(x: 0, y: 0, width: 33, height: 100))
110+
#expect(actual == CGRect(x: 0, y: 0, width: 33, height: 100))
99111
}
100112

101-
func test_makeNewFrame_左側2/3_領域が返される() async {
113+
@Test
114+
func makeNewFrame_左側2/3_領域が返される() async {
102115
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
103116
let actual = await sut.makeNewFrame(shiftType: .leftTwoThirds, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
104-
XCTAssertEqual(actual, CGRect(x: 0, y: 0, width: 66, height: 100))
117+
#expect(actual == CGRect(x: 0, y: 0, width: 66, height: 100))
105118
}
106119

107-
func test_makeNewFrame_中央1/3_領域が返される() async {
120+
@Test
121+
func makeNewFrame_中央1/3_領域が返される() async {
108122
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
109123
let actual = await sut.makeNewFrame(shiftType: .middleThird, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
110-
XCTAssertEqual(actual, CGRect(x: 33, y: 0, width: 33, height: 100))
124+
#expect(actual == CGRect(x: 33, y: 0, width: 33, height: 100))
111125
}
112126

113-
func test_makeNewFrame_右側2/3_領域が返される() async {
127+
@Test
128+
func makeNewFrame_右側2/3_領域が返される() async {
114129
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
115130
let actual = await sut.makeNewFrame(shiftType: .rightTwoThirds, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
116-
XCTAssertEqual(actual, CGRect(x: 33, y: 0, width: 67, height: 100))
131+
#expect(actual == CGRect(x: 33, y: 0, width: 67, height: 100))
117132
}
118133

119-
func test_makeNewFrame_右側1/3_領域が返される() async {
134+
@Test
135+
func makeNewFrame_右側1/3_領域が返される() async {
120136
let sut = ShiftService(.testValue, .testValue, .testValue, .testValue, .testValue)
121137
let actual = await sut.makeNewFrame(shiftType: .rightThird, validFrame: CGRect(x: 0, y: 0, width: 100, height: 100))
122-
XCTAssertEqual(actual, CGRect(x: 66, y: 0, width: 34, height: 100))
138+
#expect(actual == CGRect(x: 66, y: 0, width: 34, height: 100))
123139
}
124140
}
125141

ShiftWindowPackages/Tests/DomainTests/ServiceTests/ShortcutServiceTests.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import Foundation
12
import os
2-
import XCTest
3+
import Testing
34

45
@testable import DataLayer
56
@testable import Domain
67

7-
final class ShortcutServiceTests: XCTestCase {
8-
func test_initializeShortcuts() async {
8+
struct ShortcutServiceTests {
9+
@Test
10+
func initializeShortcuts() async {
911
let count = OSAllocatedUnfairLock(initialState: 0)
1012
let spiceKeyClient = testDependency(of: SpiceKeyClient.self) {
1113
$0.register = { _ in count.withLock { $0 += 1 } }
@@ -20,10 +22,11 @@ final class ShortcutServiceTests: XCTestCase {
2022
let sut = ShortcutService(spiceKeyClient, userDefaultsClient, .testValue)
2123
await sut.initializeShortcuts()
2224
let actual = count.withLock(\.self)
23-
XCTAssertEqual(actual, 1)
25+
#expect(actual == 1)
2426
}
2527

26-
func test_getIndex_正しくIndexが取得される() async {
28+
@Test
29+
func getIndex_正しくIndexが取得される() async {
2730
let userDefaultsClient = testDependency(of: UserDefaultsClient.self) {
2831
$0.data = { _ in
2932
try! JSONEncoder().encode([
@@ -35,6 +38,6 @@ final class ShortcutServiceTests: XCTestCase {
3538
}
3639
let sut = ShortcutService(.testValue, userDefaultsClient, .testValue)
3740
let actual = await sut.getIndex(id: ShiftType.bottomHalf.id)
38-
XCTAssertEqual(actual, 1)
41+
#expect(actual == 1)
3942
}
4043
}
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Foundation
22
import os
33
import ServiceManagement
4-
import XCTest
4+
import Testing
55

66
@testable import DataLayer
77
@testable import Domain
88

9-
final class GeneralSettingsViewModelTests: XCTestCase {
10-
@MainActor
11-
func test_openSystemSettings() async {
9+
struct GeneralSettingsViewModelTests {
10+
@MainActor @Test
11+
func openSystemSettings() async {
1212
let calledURLs = OSAllocatedUnfairLock(initialState: [URL]())
1313
let nsWorkspaceClient = testDependency(of: NSWorkspaceClient.self) {
1414
$0.open = { url in
@@ -19,52 +19,53 @@ final class GeneralSettingsViewModelTests: XCTestCase {
1919
let sut = GeneralSettingsViewModel(nsWorkspaceClient, .testValue, .testValue, .init(.testValue))
2020
sut.openSystemSettings()
2121
let actual = calledURLs.withLock(\.self)
22-
XCTAssertEqual(actual, [URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!])
22+
#expect(actual == [URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!])
2323
}
2424

25-
@MainActor
26-
func test_toggleLaunchAtLogin_有効の要求_成功した_有効に変更される() async {
25+
@MainActor @Test
26+
func toggleLaunchAtLogin_有効の要求_成功した_有効に変更される() async {
2727
let currentStatus = OSAllocatedUnfairLock(initialState: SMAppService.Status.notRegistered)
2828
let smAppServiceClient = testDependency(of: SMAppServiceClient.self) {
2929
$0.status = { currentStatus.withLock(\.self) }
3030
$0.register = { currentStatus.withLock { $0 = .enabled } }
3131
}
3232
let sut = GeneralSettingsViewModel(.testValue, .testValue, smAppServiceClient, .init(.testValue))
3333
sut.toggleLaunchAtLogin(true)
34-
XCTAssertTrue(sut.launchAtLogin)
34+
#expect(sut.launchAtLogin)
3535
}
3636

37-
@MainActor
38-
func test_toggleLaunchAtLogin_有効の要求_失敗した_無効に戻される() async {
37+
38+
@MainActor @Test
39+
func toggleLaunchAtLogin_有効の要求_失敗した_無効に戻される() async {
3940
let smAppServiceClient = testDependency(of: SMAppServiceClient.self) {
4041
$0.status = { .notRegistered }
4142
$0.register = { throw NSError(domain: "", code: kSMErrorInternalFailure) }
4243
}
4344
let sut = GeneralSettingsViewModel(.testValue, .testValue, smAppServiceClient, .init(.testValue))
4445
sut.toggleLaunchAtLogin(true)
45-
XCTAssertFalse(sut.launchAtLogin)
46+
#expect(sut.launchAtLogin == false)
4647
}
4748

48-
@MainActor
49-
func test_toggleLaunchAtLogin_無効の要求_成功した_無効に変更される() async {
49+
@MainActor @Test
50+
func toggleLaunchAtLogin_無効の要求_成功した_無効に変更される() async {
5051
let currentStatus = OSAllocatedUnfairLock(initialState: SMAppService.Status.enabled)
5152
let smAppServiceClient = testDependency(of: SMAppServiceClient.self) {
5253
$0.status = { currentStatus.withLock(\.self) }
5354
$0.unregister = { currentStatus.withLock { $0 = .notRegistered } }
5455
}
5556
let sut = GeneralSettingsViewModel(.testValue, .testValue, smAppServiceClient, .init(.testValue))
5657
sut.toggleLaunchAtLogin(false)
57-
XCTAssertFalse(sut.launchAtLogin)
58+
#expect(sut.launchAtLogin == false)
5859
}
5960

60-
@MainActor
61-
func test_toggleLaunchAtLogin_無効の要求_失敗した_有効に戻される() async {
61+
@MainActor @Test
62+
func toggleLaunchAtLogin_無効の要求_失敗した_有効に戻される() async {
6263
let smAppServiceClient = testDependency(of: SMAppServiceClient.self) {
6364
$0.status = { .enabled }
6465
$0.unregister = { throw NSError(domain: "", code: kSMErrorInternalFailure) }
6566
}
6667
let sut = GeneralSettingsViewModel(.testValue, .testValue, smAppServiceClient, .init(.testValue))
6768
sut.toggleLaunchAtLogin(false)
68-
XCTAssertTrue(sut.launchAtLogin)
69+
#expect(sut.launchAtLogin)
6970
}
7071
}

0 commit comments

Comments
 (0)