How to use HaveCountTest class

Best Nimble code snippet using .HaveCountTest

Run Nimble automation tests on LambdaTest cloud grid

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

HaveCountTest.swift

Source: HaveCountTest.swift Github

copy
1import XCTest
2import Nimble
3
4final class HaveCountTest: XCTestCase, XCTestCaseProvider {
5    static var allTests: [(String, (HaveCountTest) -> () throws -> Void)] {
6        return [
7            ("testHaveCountForArray", testHaveCountForArray),
8            ("testHaveCountForDictionary", testHaveCountForDictionary),
9            ("testHaveCountForSet", testHaveCountForSet),
10        ]
11    }
12
13    func testHaveCountForArray() {
14        expect([1, 2, 3]).to(haveCount(3))
15        expect([1, 2, 3]).notTo(haveCount(1))
16
17        failsWithErrorMessage("expected to have Array<Int> with count 1, got 3\nActual Value: [1, 2, 3]") {
18            expect([1, 2, 3]).to(haveCount(1))
19        }
20
21        failsWithErrorMessage("expected to not have Array<Int> with count 3, got 3\nActual Value: [1, 2, 3]") {
22            expect([1, 2, 3]).notTo(haveCount(3))
23        }
24    }
25
26    func testHaveCountForDictionary() {
27        let dictionary = ["1":1, "2":2, "3":3]
28        expect(dictionary).to(haveCount(3))
29        expect(dictionary).notTo(haveCount(1))
30
31        failsWithErrorMessage("expected to have Dictionary<String, Int> with count 1, got 3\nActual Value: \(stringify(dictionary))") {
32            expect(dictionary).to(haveCount(1))
33        }
34
35        failsWithErrorMessage("expected to not have Dictionary<String, Int> with count 3, got 3" +
36            "\nActual Value: \(stringify(dictionary))") {
37                expect(dictionary).notTo(haveCount(3))
38        }
39    }
40
41    func testHaveCountForSet() {
42        let set = Set([1, 2, 3])
43        expect(set).to(haveCount(3))
44        expect(set).notTo(haveCount(1))
45
46        failsWithErrorMessage("expected to have Set<Int> with count 1, got 3" +
47            "\nActual Value: \(stringify(set))") {
48                expect(set).to(haveCount(1))
49        }
50
51        failsWithErrorMessage("expected to not have Set<Int> with count 3, got 3" +
52            "\nActual Value: \(stringify(set))") {
53                expect(set).notTo(haveCount(3))
54        }
55    }
56}
57
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)