How to use testInequalityCountMatcher_atLeast_aboveThreshold method of CountMatcherTests class

Best Mockingbird code snippet using CountMatcherTests.testInequalityCountMatcher_atLeast_aboveThreshold

Run Mockingbird automation tests on LambdaTest cloud grid

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

CountMatcherTests.swift

Source: CountMatcherTests.swift Github

copy
1//
2//  CountMatcherTests.swift
3//  MockingbirdTests
4//
5//  Created by Andrew Chang on 3/2/20.
6//
7
8import Mockingbird
9import XCTest
10@testable import MockingbirdTestsHost
11
12// TODO: Create XFAIL equivalent for XCTestCase to test expected verification failures.
13class CountMatcherTests: XCTestCase {
14  
15  var child: ChildProtocolMock!
16  
17  override func setUp() {
18    child = mock(ChildProtocol.self)
19  }
20  
21  // MARK: - Adverbial counts
22  
23  // MARK: Exact
24  
25  func testAdverbialCount_exactlyNever() {
26    verify(child.childTrivialInstanceMethod()).wasCalled(never)
27    verify(child.childTrivialInstanceMethod()).wasCalled(exactly(never))
28    verify(child.childTrivialInstanceMethod()).wasNeverCalled()
29  }
30  
31  func testAdverbialCount_exactlyOnce() {
32    (child as ChildProtocol).childTrivialInstanceMethod()
33    verify(child.childTrivialInstanceMethod()).wasCalled(once)
34    verify(child.childTrivialInstanceMethod()).wasCalled(exactly(once))
35  }
36  
37  func testAdverbialCount_exactlyTwice() {
38    (child as ChildProtocol).childTrivialInstanceMethod()
39    (child as ChildProtocol).childTrivialInstanceMethod()
40    verify(child.childTrivialInstanceMethod()).wasCalled(twice)
41    verify(child.childTrivialInstanceMethod()).wasCalled(exactly(twice))
42  }
43  
44  // MARK: Inequality
45  
46  func testAdverbialCount_atMostOnce() {
47    (child as ChildProtocol).childTrivialInstanceMethod()
48    verify(child.childTrivialInstanceMethod()).wasCalled(atMost(once))
49  }
50  
51  func testAdverbialCount_atLeastOnce() {
52    (child as ChildProtocol).childTrivialInstanceMethod()
53    verify(child.childTrivialInstanceMethod()).wasCalled(atLeast(once))
54  }
55  
56  func testAdverbialCount_atMostTwice() {
57    (child as ChildProtocol).childTrivialInstanceMethod()
58    verify(child.childTrivialInstanceMethod()).wasCalled(atMost(twice))
59  }
60  
61  func testAdverbialCount_atLeastTwice() {
62    (child as ChildProtocol).childTrivialInstanceMethod()
63    (child as ChildProtocol).childTrivialInstanceMethod()
64    verify(child.childTrivialInstanceMethod()).wasCalled(atLeast(twice))
65  }
66  
67  // MARK: - Exact count matcher
68  
69  func testExactCountMatcher() {
70    (child as ChildProtocol).childTrivialInstanceMethod()
71    (child as ChildProtocol).childTrivialInstanceMethod()
72    (child as ChildProtocol).childTrivialInstanceMethod()
73    verify(child.childTrivialInstanceMethod()).wasCalled(exactly(3))
74  }
75  
76  func testExactCountMatcher_convenience() {
77    (child as ChildProtocol).childTrivialInstanceMethod()
78    (child as ChildProtocol).childTrivialInstanceMethod()
79    (child as ChildProtocol).childTrivialInstanceMethod()
80    verify(child.childTrivialInstanceMethod()).wasCalled(3)
81  }
82  
83  // MARK: - Inequality count matcher
84  
85  func testInequalityCountMatcher_atLeast_atThreshold() {
86    (child as ChildProtocol).childTrivialInstanceMethod()
87    (child as ChildProtocol).childTrivialInstanceMethod()
88    (child as ChildProtocol).childTrivialInstanceMethod()
89    verify(child.childTrivialInstanceMethod()).wasCalled(atLeast(3))
90  }
91  
92  func testInequalityCountMatcher_atLeast_aboveThreshold() {
93    (child as ChildProtocol).childTrivialInstanceMethod()
94    (child as ChildProtocol).childTrivialInstanceMethod()
95    (child as ChildProtocol).childTrivialInstanceMethod()
96    (child as ChildProtocol).childTrivialInstanceMethod()
97    verify(child.childTrivialInstanceMethod()).wasCalled(atLeast(3))
98  }
99  
100  func testInequalityCountMatcher_atMost_atThreshold() {
101    (child as ChildProtocol).childTrivialInstanceMethod()
102    (child as ChildProtocol).childTrivialInstanceMethod()
103    (child as ChildProtocol).childTrivialInstanceMethod()
104    verify(child.childTrivialInstanceMethod()).wasCalled(atMost(3))
105  }
106  
107  func testInequalityCountMatcher_atMost_belowThreshold() {
108    (child as ChildProtocol).childTrivialInstanceMethod()
109    (child as ChildProtocol).childTrivialInstanceMethod()
110    verify(child.childTrivialInstanceMethod()).wasCalled(atMost(3))
111  }
112  
113  // MARK: - Composition
114  
115  func testCountMatcherComposition_orOperator() {
116    (child as ChildProtocol).childTrivialInstanceMethod()
117    verify(child.childTrivialInstanceMethod()).wasCalled(exactly(once).or(exactly(twice)))
118    
119    (child as ChildProtocol).childTrivialInstanceMethod()
120    verify(child.childTrivialInstanceMethod()).wasCalled(exactly(once).or(exactly(twice)))
121  }
122  
123  func testCountMatcherComposition_andOperator() {
124    (child as ChildProtocol).childTrivialInstanceMethod()
125    verify(child.childTrivialInstanceMethod()).wasCalled(exactly(once).and(atMost(twice)))
126  }
127  
128  func testCountMatcherComposition_notOperator() {
129    (child as ChildProtocol).childTrivialInstanceMethod()
130    (child as ChildProtocol).childTrivialInstanceMethod()
131    verify(child.childTrivialInstanceMethod()).wasCalled(not(exactly(once)))
132  }
133  
134  func testCountMatcherComposition_notOperatorWithAndOperator() {
135    (child as ChildProtocol).childTrivialInstanceMethod()
136    (child as ChildProtocol).childTrivialInstanceMethod()
137    (child as ChildProtocol).childTrivialInstanceMethod()
138    verify(child.childTrivialInstanceMethod()).wasCalled(not(exactly(once).and(atMost(twice))))
139  }
140}
141
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
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)