Skip to content

Commit 16e9ebd

Browse files
authored
test: adds allure report for e2e (#214)
Signed-off-by: Allain Magyar <[email protected]>
1 parent 7790c97 commit 16e9ebd

38 files changed

+1442
-523
lines changed

E2E/TestFramework/Assertion/AssertionError.swift

Lines changed: 0 additions & 44 deletions
This file was deleted.

E2E/TestFramework/BDD/Feature.swift

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SwiftHamcrest
55
open class Feature: XCTestCase {
66
let id: String = UUID().uuidString
77
open var currentScenario: Scenario? = nil
8-
8+
99
open func title() -> String {
1010
fatalError("Set feature title")
1111
}
@@ -16,9 +16,23 @@ open class Feature: XCTestCase {
1616

1717
/// our lifecycle starts after xctest is ending
1818
public override func tearDown() async throws {
19-
try await run()
19+
var errorFromRun: Error?
20+
do {
21+
try await run()
22+
} catch {
23+
errorFromRun = error
24+
}
2025
self.currentScenario = nil
21-
try await super.tearDown()
26+
var superTeardownError: Error?
27+
do {
28+
try await super.tearDown()
29+
} catch {
30+
superTeardownError = error
31+
}
32+
33+
if let errorToThrow = errorFromRun ?? superTeardownError {
34+
throw errorToThrow
35+
}
2236
}
2337

2438
public override class func tearDown() {
@@ -34,30 +48,36 @@ open class Feature: XCTestCase {
3448
}
3549

3650
func run() async throws {
37-
// check if we have the scenario
38-
if (currentScenario == nil) {
39-
throw XCTSkip("""
40-
To run the feature you have to setup the scenario for each test case.
41-
Usage:
42-
func testMyScenario() async throws {
43-
scenario = Scenario("description")
44-
.given // ...
51+
let currentTestMethodName = self.name
52+
if currentScenario == nil {
53+
let rawMethodName = currentTestMethodName.split(separator: " ").last?.dropLast() ?? "yourTestMethod"
54+
55+
let errorMessage = """
56+
‼️ SCENARIO NOT DEFINED in test method: \(currentTestMethodName)
57+
Each 'func test...()' method within a 'Feature' class must assign a 'Scenario' to 'self.currentScenario'.
58+
59+
Example:
60+
func \(rawMethodName)() async throws {
61+
currentScenario = Scenario("A brief scenario description", file: #file, line: #line)
62+
.given("some precondition")
63+
.when("some action")
64+
.then("some expected outcome")
4565
}
46-
""")
66+
"""
67+
throw ConfigurationError.missingScenario(errorMessage)
4768
}
48-
49-
if (currentScenario!.disabled) {
50-
throw XCTSkip("Scenario [\(currentScenario!.title)] is disabled")
69+
if currentScenario!.disabled {
70+
throw XCTSkip("Scenario '\(currentScenario!.name)' in test method \(currentTestMethodName) is disabled.")
5171
}
52-
5372
try await TestConfiguration.setUpInstance()
5473

55-
if (currentScenario! is ParameterizedScenario) {
56-
let parameterizedScenario = currentScenario! as! ParameterizedScenario
57-
for scenario in parameterizedScenario.build() {
58-
try await TestConfiguration.shared().run(self, scenario)
74+
if let parameterizedScenario = currentScenario as? ParameterizedScenario {
75+
for scenarioInstance in parameterizedScenario.build() {
76+
scenarioInstance.feature = self
77+
try await TestConfiguration.shared().run(self, scenarioInstance)
5978
}
6079
} else {
80+
currentScenario?.feature = self
6181
try await TestConfiguration.shared().run(self, currentScenario!)
6282
}
6383
}

E2E/TestFramework/BDD/ParameterizedScenario.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import Foundation
22
import XCTest
33

44
public class ParameterizedScenario: Scenario {
5-
public var parameters: [[String: String]] = [[:]]
5+
public var table: [[String: String]] = [[:]]
66

7-
public func parameters(_ parameters: [[String: String]]) -> Scenario {
8-
self.parameters = parameters
7+
public func table(_ table: [[String: String]]) -> Scenario {
8+
self.table = table
99
return self
1010
}
1111

1212
public func build() -> [Scenario] {
1313
var scenarios: [Scenario] = []
1414

15-
parameters.forEach { parameters in
16-
let scenario = Scenario(replace(line: self.title, parameters: parameters))
15+
table.forEach { parameters in
16+
let scenario = Scenario(replace(line: self.name, parameters: parameters), parameters: parameters)
1717
scenario.steps = self.steps.map { step in
1818
let newStep = ConcreteStep()
1919
newStep.context = step.context

E2E/TestFramework/BDD/Scenario.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ import XCTest
33

44
public class Scenario {
55
let id = UUID().uuidString
6-
var title: String
6+
var name: String
77
var steps: [ConcreteStep] = []
8-
var pass: Bool = false
9-
var error: Error? = nil
108
var disabled: Bool = false
11-
9+
var feature: Feature?
10+
var parameters: [String: String]?
11+
1212
private var lastContext: String = ""
1313

14-
public init(_ title: String) {
15-
self.title = title
14+
public init(_ title: String, parameters: [String: String] = [:]) {
15+
self.name = title
16+
self.parameters = parameters
1617
}
1718

1819
public func fail(file: StaticString?, line: UInt?, message: String) {

E2E/TestFramework/Configuration/ITestConfiguration.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Foundation
22

33
public protocol ITestConfiguration {
4-
static var shared: () -> ITestConfiguration {get}
5-
static func createInstance() -> ITestConfiguration
6-
7-
func run(_ feature: Feature, _ currentScenario: Scenario) async throws
4+
static var shared: () -> TestConfiguration {get}
5+
static func createInstance() -> TestConfiguration
6+
7+
func run(_ feature: Feature, _ currentScenario: Scenario?) async throws
88

99
/// setup
1010
func setUp() async throws

0 commit comments

Comments
 (0)