How to use ThrowAssertionTest class

Best Nimble code snippet using .ThrowAssertionTest

Run Nimble automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ThrowAssertionTest.swift

Source: ThrowAssertionTest.swift Github

copy
1import Foundation
2import XCTest
3import Nimble
4
5#if _runtime(_ObjC) && !SWIFT_PACKAGE
6
7final class ThrowAssertionTest: XCTestCase, XCTestCaseProvider {
8    static var allTests: [(String, (ThrowAssertionTest) -> () throws -> Void)] {
9        return [
10            ("testPositiveMatch", testPositiveMatch),
11            ("testErrorThrown", testErrorThrown),
12            ("testPostAssertionCodeNotRun", testPostAssertionCodeNotRun),
13            ("testNegativeMatch", testNegativeMatch),
14            ("testPositiveMessage", testPositiveMessage),
15            ("testNegativeMessage", testNegativeMessage),
16        ]
17    }
18
19    func testPositiveMatch() {
20        expect { () -> Void in fatalError() }.to(throwAssertion())
21    }
22
23    func testErrorThrown() {
24        expect { throw NSError(domain: "test", code: 0, userInfo: nil) }.toNot(throwAssertion())
25    }
26
27    func testPostAssertionCodeNotRun() {
28        var reachedPoint1 = false
29        var reachedPoint2 = false
30
31        expect {
32            reachedPoint1 = true
33            precondition(false, "condition message")
34            reachedPoint2 = true
35        }.to(throwAssertion())
36
37        expect(reachedPoint1) == true
38        expect(reachedPoint2) == false
39    }
40
41    func testNegativeMatch() {
42        var reachedPoint1 = false
43
44        expect { reachedPoint1 = true }.toNot(throwAssertion())
45        
46        expect(reachedPoint1) == true
47    }
48
49    func testPositiveMessage() {
50        failsWithErrorMessage("expected to throw an assertion") {
51            expect { () -> Void? in return }.to(throwAssertion())
52        }
53    }
54
55    func testNegativeMessage() {
56        failsWithErrorMessage("expected to not throw an assertion") {
57            expect { () -> Void in fatalError() }.toNot(throwAssertion())
58        }
59    }
60}
61
62#endif
63
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)