How to use ExampleGroup class

Best Quick code snippet using .ExampleGroup

Run Quick automation tests on LambdaTest cloud grid

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

ExampleGroup.swift

Source: ExampleGroup.swift Github

copy
1import Foundation
2
3/**
4    Example groups are logical groupings of examples, defined with
5    the `describe` and `context` functions. Example groups can share
6    setup and teardown code.
7*/
8final public class ExampleGroup: NSObject {
9    weak internal var parent: ExampleGroup?
10    internal let hooks = ExampleHooks()
11    
12    internal var phase: HooksPhase = .NothingExecuted
13
14    private let internalDescription: String
15    private let flags: FilterFlags
16    private let isInternalRootExampleGroup: Bool
17    private var childGroups = [ExampleGroup]()
18    private var childExamples = [Example]()
19
20    internal init(description: String, flags: FilterFlags, isInternalRootExampleGroup: Bool = false) {
21        self.internalDescription = description
22        self.flags = flags
23        self.isInternalRootExampleGroup = isInternalRootExampleGroup
24    }
25
26    public override var description: String {
27        return internalDescription
28    }
29
30    /**
31        Returns a list of examples that belong to this example group,
32        or to any of its descendant example groups.
33    */
34    public var examples: [Example] {
35        var examples = childExamples
36        for group in childGroups {
37            examples.appendContentsOf(group.examples)
38        }
39        return examples
40    }
41
42    internal var name: String? {
43        if let parent = parent {
44            switch(parent.name) {
45            case .Some(let name): return "\(name), \(description)"
46            case .None: return description
47            }
48        } else {
49            return isInternalRootExampleGroup ? nil : description
50        }
51    }
52
53    internal var filterFlags: FilterFlags {
54        var aggregateFlags = flags
55        walkUp() { (group: ExampleGroup) -> () in
56            for (key, value) in group.flags {
57                aggregateFlags[key] = value
58            }
59        }
60        return aggregateFlags
61    }
62
63    internal var befores: [BeforeExampleWithMetadataClosure] {
64        var closures = Array(hooks.befores.reverse())
65        walkUp() { (group: ExampleGroup) -> () in
66            closures.appendContentsOf(Array(group.hooks.befores.reverse()))
67        }
68        return Array(closures.reverse())
69    }
70
71    internal var afters: [AfterExampleWithMetadataClosure] {
72        var closures = hooks.afters
73        walkUp() { (group: ExampleGroup) -> () in
74            closures.appendContentsOf(group.hooks.afters)
75        }
76        return closures
77    }
78
79    internal func walkDownExamples(callback: (example: Example) -> ()) {
80        for example in childExamples {
81            callback(example: example)
82        }
83        for group in childGroups {
84            group.walkDownExamples(callback)
85        }
86    }
87
88    internal func appendExampleGroup(group: ExampleGroup) {
89        group.parent = self
90        childGroups.append(group)
91    }
92
93    internal func appendExample(example: Example) {
94        example.group = self
95        childExamples.append(example)
96    }
97
98    private func walkUp(callback: (group: ExampleGroup) -> ()) {
99        var group = self
100        while let parent = group.parent {
101            callback(group: parent)
102            group = parent
103        }
104    }
105}
106
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

Most used methods in ExampleGroup

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)