Hi,
I create a ModelContainer in test class.
final class NewNotPaidTrTest: XCTestCase {
@MainActor
let testContainer: ModelContainer = {
do {
let container = try ModelContainer (for: Category.self, Account.self, Transaction.self, configurations: ModelConfiguration(isStoredInMemoryOnly: true))
container.mainContext.insert(Category.preview)
container.mainContext.insert(Account.preview)
return container
} catch {
fatalError("Failed to create container")
}
}()
@MainActor func testNewNotPaidTr() throws {
let tr = Transaction(amount: 1000, date: Date.now, notes: "", isMovement: false, isPaid: false, planAuto: false)
debugPrint(Account.preview.name)
testContainer.mainContext.insert(tr)
tr.account = Account.preview
tr.category = Category.preview
Account.updateBalance(tr, isAddTr: true)
XCTAssertEqual(tr.account!.balance, 123400, "Fallita -> \(tr.account!.balance)")
do {
try testContainer.mainContext.save()
} catch {
fatalError("Failed to save")
}
testContainer.mainContext.delete(tr)
Account.updateBalance(tr, isAddTr: false)
XCTAssertEqual(tr.account!.balance, 123400, "Fallita -> \(tr.account!.balance)")
}
}
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: