Skip to content

A previews-based unit testing framework suitable for Swift Playgrounds Apps.

License

Notifications You must be signed in to change notification settings

MutatingFunc/UnitTestingPreviews

Repository files navigation

UnitTestingPreviews

A previews-based unit testing framework suitable for Swift Playgrounds Apps.

Usage:


struct Doofer {
    func doof() -> String {
        "doof"
    }
    
    func longDoof() async -> String {
        try? await Task.sleep(for: .seconds(1))
        return "doof"
    }
    
    func doof(_ grog: String) -> String {
        grog + "doof"
    }
}

struct Doofer_Tests: TestCase, PreviewProvider {
    static var tests: some View  {
        Test(title: "Doofer doof() returns doof") {
            let doofer = Doofer()
            
            let result = doofer.doof()
            
            AssertEqual(result, "doof")
            AssertEqual(result, "doofette")
            AssertGreaterThan(result, "dooa")
            AssertContains(result, "d")            
            AssertContains(result, "d")            
            AssertNot(AssertContains(result, "a")) 
            AssertContains(["doof", "nork"], result)
            if result.count > 3 {
                Assert(true, message: "Is doof")
            } else {
                Assert(false, message: "Is not doof")
            }
            if result.count > 4 {
                Assert(true, message: "Is doof")
            }
            for i in 0..<20 {
                Assert(i%2==0, message: "Is \(i) even")
            }
        }
        Test(title: "Doofer longDoof() returns doof") {
            let doofer = Doofer()
            
            let result = await doofer.longDoof()
            
            AssertEqual(result, "doof")   
        }
    }
}

image

About

A previews-based unit testing framework suitable for Swift Playgrounds Apps.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages