Improve test assertions for better clarity

- Remove redundant bundle ID checks in ApplicationFinderTests
- Replace do-catch with #expect(throws:) for cleaner error testing
- Simplify permission test assertions to avoid false failures
- Remove unnecessary boolean comparisons in permission checks

These changes make the tests more maintainable and less prone to
environment-specific failures.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Peter Steinberger 2025-06-08 11:23:43 +01:00
parent c04b8e7af0
commit 612f69f459
3 changed files with 18 additions and 28 deletions

View file

@ -96,10 +96,7 @@ struct ApplicationFinderTests {
for app in apps {
#expect(!app.app_name.isEmpty)
// Some system processes may have empty bundle IDs
if !app.bundle_id.isEmpty {
#expect(!app.bundle_id.isEmpty)
}
// Some system processes may have empty bundle IDs - no need to check twice
#expect(app.pid > 0)
#expect(app.window_count >= 0)
}
@ -118,8 +115,8 @@ struct ApplicationFinderTests {
#expect(result.localizedName != nil)
#expect(!result.localizedName!.isEmpty)
} catch {
// Expected if app is not installed
#expect(Bool(true))
// Expected if app is not installed - no assertion needed
continue
}
}
}
@ -379,27 +376,18 @@ struct ApplicationFinderEdgeCaseTests {
}
@Test("Fuzzy matching finds similar apps", .tags(.fast))
func fuzzyMatchingFindsSimilarApps() {
func fuzzyMatchingFindsSimilarApps() throws {
// Test that fuzzy matching can find apps with typos
do {
let result = try ApplicationFinder.findApplication(identifier: "Finderr")
// Should find "Finder" despite the typo
#expect(result.localizedName?.lowercased().contains("finder") == true)
} catch {
Issue.record("Fuzzy matching should have found Finder for 'Finderr', got error: \(error)")
}
let result = try ApplicationFinder.findApplication(identifier: "Finderr")
// Should find "Finder" despite the typo
#expect(result.localizedName?.lowercased().contains("finder") == true)
}
@Test("Non-existent app throws error", .tags(.fast))
func nonExistentAppThrowsError() {
// Test with a completely non-existent app name
do {
#expect(throws: ApplicationError.notFound("XyzNonExistentApp123")) {
_ = try ApplicationFinder.findApplication(identifier: "XyzNonExistentApp123")
Issue.record("Expected error for non-existent app 'XyzNonExistentApp123'")
} catch let ApplicationError.notFound(identifier) {
#expect(identifier == "XyzNonExistentApp123")
} catch {
Issue.record("Expected ApplicationError.notFound, got \(error)")
}
}

View file

@ -11,9 +11,9 @@ struct PermissionsCheckerTests {
// Test screen recording permission check
let hasPermission = PermissionsChecker.checkScreenRecordingPermission()
// This test will pass or fail based on actual system permissions
// The result should be a valid boolean
#expect(hasPermission == true || hasPermission == false)
// Just verify we got a valid boolean result (the API works)
// The actual value depends on system permissions
_ = hasPermission
}
@Test("Screen recording permission check is consistent", .tags(.fast))
@ -28,8 +28,8 @@ struct PermissionsCheckerTests {
@Test("Screen recording permission check performance", arguments: 1...5)
func screenRecordingPermissionPerformance(iteration: Int) {
// Permission checks should be fast
let hasPermission = PermissionsChecker.checkScreenRecordingPermission()
#expect(hasPermission == true || hasPermission == false)
_ = PermissionsChecker.checkScreenRecordingPermission()
// Performance is measured by the test framework's execution time
}
// MARK: - Accessibility Permission Tests
@ -39,8 +39,9 @@ struct PermissionsCheckerTests {
// Test accessibility permission check
let hasPermission = PermissionsChecker.checkAccessibilityPermission()
// This will return the actual system state
#expect(hasPermission == true || hasPermission == false)
// Just verify we got a valid boolean result (the API works)
// The actual value depends on system permissions
_ = hasPermission
}
@Test("Accessibility permission matches AXIsProcessTrusted", .tags(.fast))

View file

@ -210,7 +210,8 @@ struct WindowManagerAdvancedTests {
let apps = NSWorkspace.shared.runningApplications
guard let app = apps.first(where: { $0.bundleIdentifier == bundleId }) else {
return // Skip test if app not running
// Use Swift Testing's conditional execution instead of return
throw XCTSkip("App with bundle ID \(bundleId) is not running")
}
let windows = try WindowManager.getWindowsForApp(pid: app.processIdentifier)