テスト自動化と品質担保の強化
- CalendarServiceに対するユニットテスト(ロード、保存の挙動)を実装 - Makefileにtestターゲットを追加し、コマンドラインからテスト実行を可能化 - Xcodeプロジェクト(yml)にテストターゲット(OreCalendarTests)とtest定義を追加
This commit is contained in:
5
Makefile
5
Makefile
@@ -1,4 +1,4 @@
|
||||
.PHONY: generate build all
|
||||
.PHONY: generate build all test
|
||||
|
||||
all: build
|
||||
|
||||
@@ -7,6 +7,9 @@ generate:
|
||||
build: generate
|
||||
xcodebuild -scheme OreCalendar -destination 'platform=macOS' -derivedDataPath build build
|
||||
|
||||
test: generate
|
||||
xcodebuild test -scheme OreCalendar -destination 'platform=macOS' -derivedDataPath build
|
||||
|
||||
release: build
|
||||
rm -rf ~/Applications/OreCalendar.app ; true
|
||||
mv build/Build/Products/Release/OreCalendar.app ~/Applications/OreCalendar.app
|
||||
|
||||
50
Tests/CalendarServiceTests.swift
Normal file
50
Tests/CalendarServiceTests.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
import XCTest
|
||||
import EventKit
|
||||
@testable import OreCalendar
|
||||
|
||||
@MainActor
|
||||
final class CalendarServiceTests: XCTestCase {
|
||||
var service: CalendarService!
|
||||
let testKey = "selectedCalendars"
|
||||
|
||||
override func setUp() async throws {
|
||||
try await super.setUp()
|
||||
service = CalendarService()
|
||||
UserDefaults.standard.removeObject(forKey: testKey)
|
||||
}
|
||||
|
||||
override func tearDown() async throws {
|
||||
UserDefaults.standard.removeObject(forKey: testKey)
|
||||
service = nil
|
||||
try await super.tearDown()
|
||||
}
|
||||
|
||||
func testLoadDefaultSelectedCalendars_withSavedCalendars() async throws {
|
||||
let savedCalendarIDs = ["calendar1", "calendar2", "calendar3"]
|
||||
UserDefaults.standard.set(savedCalendarIDs, forKey: testKey)
|
||||
|
||||
service.loadDefaultSelectedCalendars()
|
||||
|
||||
XCTAssertEqual(service.selectedCalendars, Set(savedCalendarIDs))
|
||||
}
|
||||
|
||||
func testLoadDefaultSelectedCalendars_withoutSavedCalendars() async throws {
|
||||
UserDefaults.standard.removeObject(forKey: testKey)
|
||||
|
||||
service.loadDefaultSelectedCalendars()
|
||||
|
||||
let expectedCalendarIDs = Set(service.availableCalendars.map { $0.calendarIdentifier })
|
||||
XCTAssertEqual(service.selectedCalendars, expectedCalendarIDs)
|
||||
}
|
||||
|
||||
func testSaveSelectedCalendars() async throws {
|
||||
let testCalendarIDs = ["cal1", "cal2", "cal3"]
|
||||
service.selectedCalendars = Set(testCalendarIDs)
|
||||
|
||||
service.saveSelectedCalendars()
|
||||
|
||||
let savedCalendars = UserDefaults.standard.array(forKey: testKey) as? [String]
|
||||
XCTAssertNotNil(savedCalendars)
|
||||
XCTAssertEqual(Set(savedCalendars!), Set(testCalendarIDs))
|
||||
}
|
||||
}
|
||||
12
project.yml
12
project.yml
@@ -11,6 +11,9 @@ schemes:
|
||||
config: Release
|
||||
archive:
|
||||
config: Release
|
||||
test:
|
||||
targets:
|
||||
- OreCalendarTests
|
||||
targets:
|
||||
OreCalendar:
|
||||
platform: macOS
|
||||
@@ -29,4 +32,13 @@ targets:
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon
|
||||
INFOPLIST_KEY_NSCalendarsUsageDescription: "カレンダーのイベントを表示するためにアクセスが必要です"
|
||||
INFOPLIST_KEY_NSCalendarsFullAccessUsageDescription: "カレンダーのイベントを表示するためにフルアクセスが必要です"
|
||||
OreCalendarTests:
|
||||
platform: macOS
|
||||
type: bundle.unit-test
|
||||
sources:
|
||||
- Tests
|
||||
dependencies:
|
||||
- target: OreCalendar
|
||||
settings:
|
||||
GENERATE_INFOPLIST_FILE: true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user