Swiftpack.co - 0xOpenBytes/Test as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by 0xOpenBytes.
0xOpenBytes/Test 0.1.0
🧪 Expect and assert
⭐️ 2
🕓 3 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/0xOpenBytes/Test.git", from: "0.1.0")

Test

🧪 Expect and assert

What is Test?

Test is a simple testing function that allows you to create test suites with multiple steps, expectations, and assertions. You can specify a name for the test suite, an instance of the Tester class to be used for running the tests, and a closure that contains the test steps.

Where can Test be used?

Test can be used anywhere! Test can be used to test quickly inside a function to make sure something is working as expected. It is especially useful when you want to test a complex piece of code with multiple steps and assertions. Test can even be used for your unit tests!

Examples

Simple test with assertions

try await Test(named: "Test someMethod()") { tester in
    try tester.assert(SomeClass.someMethod())
    try await tester.assertNoThrows(try await SomeClass.someOtherMethod())
    try tester.assert(SomeClass.someBooleanValue, isEqualTo: false)
}

Test with expectations

try Test(named: "Test someMethod() with expectations") { tester in
    try Expect("First step should succeed") {
        try SomeClass.someMethod()
    }
    
    tester.logInfo("Just finished first step")

    try Expect("Second step should succeed") {
        try SomeClass.someOtherMethod()
    }
            
    tester.logWarning("Something unexpected happened during the second step")

    try Expect("Final assertion should be true") {
        try tester.assert(SomeClass.someBooleanValue)
    }
    
    tester.logSuccess("All steps and assertions passed!")
}

GitHub

link
Stars: 2
Last commit: 7 hours ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

0.1.0
3 weeks ago

Test

Expect and assert

What is Test?

Test is a simple testing function that allows you to create test suites with multiple steps, expectations, and assertions. You can specify a name for the test suite, an instance of the Tester class to be used for running the tests, and a closure that contains the test steps.

Where can Test be used?

Test can be used anywhere! Test can be used to test quickly inside a function to make sure something is working as expected. It is especially useful when you want to test a complex piece of code with multiple steps and assertions. Test can even be used for your unit tests!

Examples

Simple test with assertions

try await Test(named: "Test someMethod()") { tester in
    try tester.assert(SomeClass.someMethod())
    try await tester.assertNoThrows(try await SomeClass.someOtherMethod())
    try tester.assert(SomeClass.someBooleanValue, isEqualTo: false)
}

Test with expectations

try Test(named: "Test someMethod() with expectations") { tester in
    try Expect("First step should succeed") {
        try SomeClass.someMethod()
    }
    
    tester.logInfo("Just finished first step")

    try Expect("Second step should succeed") {
        try SomeClass.someOtherMethod()
    }
            
    tester.logWarning("Something unexpected happened during the second step")

    try Expect("Final assertion should be true") {
        try tester.assert(SomeClass.someBooleanValue)
    }
    
    tester.logSuccess("All steps and assertions passed!")
}

Full Changelog: https://github.com/0xLeif/Test/commits/0.1.0

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics