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 { for app in apps {
#expect(!app.app_name.isEmpty) #expect(!app.app_name.isEmpty)
// Some system processes may have empty bundle IDs // Some system processes may have empty bundle IDs - no need to check twice
if !app.bundle_id.isEmpty {
#expect(!app.bundle_id.isEmpty)
}
#expect(app.pid > 0) #expect(app.pid > 0)
#expect(app.window_count >= 0) #expect(app.window_count >= 0)
} }
@ -118,8 +115,8 @@ struct ApplicationFinderTests {
#expect(result.localizedName != nil) #expect(result.localizedName != nil)
#expect(!result.localizedName!.isEmpty) #expect(!result.localizedName!.isEmpty)
} catch { } catch {
// Expected if app is not installed // Expected if app is not installed - no assertion needed
#expect(Bool(true)) continue
} }
} }
} }
@ -379,27 +376,18 @@ struct ApplicationFinderEdgeCaseTests {
} }
@Test("Fuzzy matching finds similar apps", .tags(.fast)) @Test("Fuzzy matching finds similar apps", .tags(.fast))
func fuzzyMatchingFindsSimilarApps() { func fuzzyMatchingFindsSimilarApps() throws {
// Test that fuzzy matching can find apps with typos // Test that fuzzy matching can find apps with typos
do { let result = try ApplicationFinder.findApplication(identifier: "Finderr")
let result = try ApplicationFinder.findApplication(identifier: "Finderr") // Should find "Finder" despite the typo
// Should find "Finder" despite the typo #expect(result.localizedName?.lowercased().contains("finder") == true)
#expect(result.localizedName?.lowercased().contains("finder") == true)
} catch {
Issue.record("Fuzzy matching should have found Finder for 'Finderr', got error: \(error)")
}
} }
@Test("Non-existent app throws error", .tags(.fast)) @Test("Non-existent app throws error", .tags(.fast))
func nonExistentAppThrowsError() { func nonExistentAppThrowsError() {
// Test with a completely non-existent app name // Test with a completely non-existent app name
do { #expect(throws: ApplicationError.notFound("XyzNonExistentApp123")) {
_ = try ApplicationFinder.findApplication(identifier: "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 // Test screen recording permission check
let hasPermission = PermissionsChecker.checkScreenRecordingPermission() let hasPermission = PermissionsChecker.checkScreenRecordingPermission()
// This test will pass or fail based on actual system permissions // Just verify we got a valid boolean result (the API works)
// The result should be a valid boolean // The actual value depends on system permissions
#expect(hasPermission == true || hasPermission == false) _ = hasPermission
} }
@Test("Screen recording permission check is consistent", .tags(.fast)) @Test("Screen recording permission check is consistent", .tags(.fast))
@ -28,8 +28,8 @@ struct PermissionsCheckerTests {
@Test("Screen recording permission check performance", arguments: 1...5) @Test("Screen recording permission check performance", arguments: 1...5)
func screenRecordingPermissionPerformance(iteration: Int) { func screenRecordingPermissionPerformance(iteration: Int) {
// Permission checks should be fast // Permission checks should be fast
let hasPermission = PermissionsChecker.checkScreenRecordingPermission() _ = PermissionsChecker.checkScreenRecordingPermission()
#expect(hasPermission == true || hasPermission == false) // Performance is measured by the test framework's execution time
} }
// MARK: - Accessibility Permission Tests // MARK: - Accessibility Permission Tests
@ -39,8 +39,9 @@ struct PermissionsCheckerTests {
// Test accessibility permission check // Test accessibility permission check
let hasPermission = PermissionsChecker.checkAccessibilityPermission() let hasPermission = PermissionsChecker.checkAccessibilityPermission()
// This will return the actual system state // Just verify we got a valid boolean result (the API works)
#expect(hasPermission == true || hasPermission == false) // The actual value depends on system permissions
_ = hasPermission
} }
@Test("Accessibility permission matches AXIsProcessTrusted", .tags(.fast)) @Test("Accessibility permission matches AXIsProcessTrusted", .tags(.fast))

View file

@ -210,7 +210,8 @@ struct WindowManagerAdvancedTests {
let apps = NSWorkspace.shared.runningApplications let apps = NSWorkspace.shared.runningApplications
guard let app = apps.first(where: { $0.bundleIdentifier == bundleId }) else { 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) let windows = try WindowManager.getWindowsForApp(pid: app.processIdentifier)