How to use testNoInvocationsBefore_arbitraryPaddingAfter method of XFailOrderedVerificationTests class

Best Mockingbird code snippet using XFailOrderedVerificationTests.testNoInvocationsBefore_arbitraryPaddingAfter

Run Mockingbird automation tests on LambdaTest cloud grid

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

XFailOrderedVerificationTests.swift

Source: XFailOrderedVerificationTests.swift Github

copy
1//
2//  XFailOrderedVerificationTests.swift
3//  MockingbirdTests
4//
5//  Created by Andrew Chang on 3/12/20.
6//
7
8import XCTest
9import Mockingbird
10@testable import MockingbirdTestsHost
11
12class XFailOrderedVerificationTests: BaseTestCase {
13  
14  var child: ChildMock!
15  
16  override func setUp() {
17    child = mock(Child.self)
18    given(child.childParameterizedInstanceMethod(param1: any(), any())) ~> true
19  }
20  
21  // MARK: - Relative ordering
22  
23  func testRelativeOrderVerification_trivialComparison() {
24    let child: ChildMock = self.child
25    shouldFail {
26      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
27      (child as Child).childTrivialInstanceMethod()
28      
29      inOrder {
30        verify(child.childTrivialInstanceMethod()).wasCalled()
31        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
32      }
33    }
34  }
35  
36  func testRelativeOrderVerification_trivialComparisonWithPaddingBefore() {
37    let child: ChildMock = self.child
38    shouldFail {
39      // Padding
40      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
41      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
42      
43      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
44      (child as Child).childTrivialInstanceMethod()
45      
46      inOrder {
47        verify(child.childTrivialInstanceMethod()).wasCalled()
48        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
49      }
50    }
51  }
52  
53  func testRelativeOrderVerification_trivialComparisonWithPaddingBetween() {
54    let child: ChildMock = self.child
55    shouldFail {
56      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
57      
58      // Padding
59      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
60      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
61      
62      (child as Child).childTrivialInstanceMethod()
63      
64      inOrder {
65        verify(child.childTrivialInstanceMethod()).wasCalled()
66        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
67      }
68    }
69  }
70  
71  func testRelativeOrderVerification_trivialComparisonWithPaddingAfter() {
72    let child: ChildMock = self.child
73    shouldFail {
74      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
75      (child as Child).childTrivialInstanceMethod()
76      
77      // Padding
78      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
79      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
80      
81      inOrder {
82        verify(child.childTrivialInstanceMethod()).wasCalled()
83        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
84      }
85    }
86  }
87  
88  func testRelativeOrderVerification_multipleSameInvocationsBefore() {
89    let child: ChildMock = self.child
90    shouldFail {
91      (child as Child).childTrivialInstanceMethod()
92      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
93      (child as Child).childTrivialInstanceMethod()
94      
95      inOrder {
96        verify(child.childTrivialInstanceMethod()).wasCalled()
97        verify(child.childTrivialInstanceMethod()).wasCalled()
98        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
99        verify(child.childTrivialInstanceMethod()).wasCalled()
100      }
101    }
102  }
103  
104  func testRelativeOrderVerification_multipleSameInvocationsAfter() {
105    let child: ChildMock = self.child
106    shouldFail {
107      (child as Child).childTrivialInstanceMethod()
108      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
109      (child as Child).childTrivialInstanceMethod()
110      
111      inOrder {
112        verify(child.childTrivialInstanceMethod()).wasCalled()
113        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
114        verify(child.childTrivialInstanceMethod()).wasCalled()
115        verify(child.childTrivialInstanceMethod()).wasCalled()
116      }
117    }
118  }
119  
120  func testRelativeOrderVerification_handlesExactCountMatcher() {
121    let child: ChildMock = self.child
122    shouldFail {
123      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
124      (child as Child).childTrivialInstanceMethod()
125      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
126      
127      inOrder {
128        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
129        verify(child.childTrivialInstanceMethod()).wasCalled(twice)
130        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
131      }
132    }
133  }
134  
135  func testRelativeOrderVerification_handlesAtLeastCountMatcher() {
136    let child: ChildMock = self.child
137    shouldFail {
138      (child as Child).childTrivialInstanceMethod()
139      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
140      
141      inOrder {
142        verify(child.childTrivialInstanceMethod()).wasCalled(atLeast(twice))
143        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
144      }
145    }
146  }
147  
148  func testRelativeOrderVerification_handlesAtLeastCountMatcher_validPaddingBefore() {
149    let child: ChildMock = self.child
150    shouldFail {
151      // Padding
152      (child as Child).childTrivialInstanceMethod()
153      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
154      
155      (child as Child).childTrivialInstanceMethod()
156      (child as Child).childTrivialInstanceMethod()
157      (child as Child).childTrivialInstanceMethod()
158      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
159      
160      inOrder {
161        verify(child.childTrivialInstanceMethod()).wasCalled(atLeast(twice))
162        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
163      }
164    }
165  }
166  
167  func testRelativeOrderVerification_handlesAtLeastCountMatcher_validPaddingBetween() {
168    let child: ChildMock = self.child
169    shouldFail {
170      (child as Child).childTrivialInstanceMethod()
171      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
172      (child as Child).childTrivialInstanceMethod()
173      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
174      
175      inOrder {
176        verify(child.childTrivialInstanceMethod()).wasCalled(atLeast(twice))
177        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
178      }
179    }
180  }
181  
182  func testRelativeOrderVerification_handlesAtMostCountMatcher() {
183    let child: ChildMock = self.child
184    shouldFail {
185      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
186      (child as Child).childTrivialInstanceMethod()
187      (child as Child).childTrivialInstanceMethod()
188      (child as Child).childTrivialInstanceMethod()
189      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
190      
191      inOrder {
192        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
193        verify(child.childTrivialInstanceMethod()).wasCalled(atMost(twice))
194        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
195      }
196    }
197  }
198  
199  func testRelativeOrderVerification_handlesAtMostCountMatcher_validPaddingBefore() {
200    let child: ChildMock = self.child
201    shouldFail {
202      // Padding
203      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
204      (child as Child).childTrivialInstanceMethod()
205      (child as Child).childTrivialInstanceMethod()
206      (child as Child).childTrivialInstanceMethod()
207      
208      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
209      (child as Child).childTrivialInstanceMethod()
210      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
211      
212      inOrder {
213        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
214        verify(child.childTrivialInstanceMethod()).wasCalled(atMost(twice))
215        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
216      }
217    }
218  }
219  
220  
221  // MARK: - Only consecutive invocations
222  
223  func testOnlyConsecutiveInvocations_paddingBetween() {
224    let child: ChildMock = self.child
225    shouldFail {
226      (child as Child).childTrivialInstanceMethod()
227      
228      // Padding
229      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
230      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
231      
232      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
233      
234      inOrder(with: .onlyConsecutiveInvocations) {
235        verify(child.childTrivialInstanceMethod()).wasCalled()
236        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
237      }
238    }
239  }
240  
241  
242  // MARK: - No invocations before
243  
244  func testNoInvocationsBefore_arbitraryPaddingBefore() {
245    let child: ChildMock = self.child
246    shouldFail {
247      // Padding
248      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
249      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
250      
251      (child as Child).childTrivialInstanceMethod()
252      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
253      
254      inOrder(with: .noInvocationsBefore) {
255        verify(child.childTrivialInstanceMethod()).wasCalled()
256        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
257      }
258    }
259  }
260  
261  func testNoInvocationsBefore_validPaddingBefore() {
262    let child: ChildMock = self.child
263    shouldFail {
264    // Padding
265      (child as Child).childTrivialInstanceMethod()
266      
267      (child as Child).childTrivialInstanceMethod()
268      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
269      
270      inOrder(with: .noInvocationsBefore) {
271        verify(child.childTrivialInstanceMethod()).wasCalled()
272        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
273      }
274    }
275  }
276  
277  
278  // MARK: - No invocations after
279  
280  func testNoInvocationsBefore_arbitraryPaddingAfter() {
281    let child: ChildMock = self.child
282    shouldFail {
283      (child as Child).childTrivialInstanceMethod()
284      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
285      
286      // Padding
287      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
288      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: false, 1337))
289      
290      inOrder(with: .noInvocationsAfter) {
291        verify(child.childTrivialInstanceMethod()).wasCalled()
292        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
293      }
294    }
295  }
296  
297  func testNoInvocationsBefore_validPaddingAfter() {
298    let child: ChildMock = self.child
299    shouldFail {
300      (child as Child).childTrivialInstanceMethod()
301      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
302      
303      // Padding
304      XCTAssertTrue((child as Child).childParameterizedInstanceMethod(param1: true, 42))
305      
306      inOrder(with: .noInvocationsAfter) {
307        verify(child.childTrivialInstanceMethod()).wasCalled()
308        verify(child.childParameterizedInstanceMethod(param1: true, 42)).wasCalled()
309      }
310    }
311  }
312}
313
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)