swift test
swift test --filter UserTests
swift test --filter RoomTests
swift test --filter RoomServiceTests
swift test --verbose
Tests/Models/)UserTests.swift - User model validationRoomTests.swift - Room management and rolesChessTests.swift - Game models and piecesTests/Services/)RoomServiceTests.swift - Room CRUD operationsChessServiceTests.swift - Game logic and stateTests/ViewModels/)RoomListViewModelTests.swift - Room list managementChessViewModelTests.swift - Game UI logicCurrent coverage areas:
✅ Models
✅ Services
✅ ViewModels
import Testing
@testable import Layover
@Suite("My Feature Tests")
struct MyFeatureTests {
@Test("Test description")
func testSomething() async throws {
// Arrange
let service = MyService()
// Act
let result = try await service.doSomething()
// Assert
#expect(result.isValid)
}
}
@Test("Async operation")
func testAsync() async throws {
let viewModel = MyViewModel()
await viewModel.loadData()
#expect(viewModel.data.isEmpty == false)
}
@Test("Error handling")
func testError() async {
let service = MyService()
await #expect(throws: MyError.self) {
try await service.failingOperation()
}
}
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: macos-14
steps:
- uses: actions/checkout@v3
- name: Run tests
run: swift test
Configure in App Store Connect with:
final class MockRoomService: RoomServiceProtocol {
var rooms: [Room] = []
var createRoomCalled = false
func createRoom(name: String, hostID: UUID, activityType: RoomActivityType) async throws -> Room {
createRoomCalled = true
let room = Room(name: name, hostID: hostID, activityType: activityType)
rooms.append(room)
return room
}
// Implement other protocol methods...
}
@Test("ViewModel uses service")
func testViewModelWithMock() async {
let mockService = MockRoomService()
let viewModel = RoomListViewModel(roomService: mockService)
await viewModel.createRoom(name: "Test", hostID: UUID(), activityType: .appleTVPlus)
#expect(mockService.createRoomCalled)
}
@Test("Performance test")
func testPerformance() async throws {
let service = TexasHoldemService()
let roomID = UUID()
let players = Array(repeating: UUID(), count: 10)
// Measure time
let start = Date()
_ = try await service.startGame(roomID: roomID, players: players)
let duration = Date().timeIntervalSince(start)
#expect(duration < 1.0) // Should complete in under 1 second
}
@Test("Debug test")
func testWithDebug() {
let value = calculateSomething()
print("Debug value: \(value)")
#expect(value > 0)
}
@Test("iOS only test")
@available(iOS 17.0, *)
func testIOSFeature() {
// iOS-specific test
}
extension Room {
static func testRoom(activityType: RoomActivityType = .appleTVPlus) -> Room {
Room(
name: "Test Room",
hostID: UUID(),
activityType: activityType
)
}
}
// Usage in tests
@Test("Using test factory")
func testWithFactory() {
let room = Room.testRoom(activityType: .texasHoldem)
#expect(room.activityType == .texasHoldem)
}
Regular test maintenance: