Skip to content

test: adds allure report for e2e #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions E2E/TestFramework/Assertion/AssertionError.swift

This file was deleted.

60 changes: 40 additions & 20 deletions E2E/TestFramework/BDD/Feature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SwiftHamcrest
open class Feature: XCTestCase {
let id: String = UUID().uuidString
open var currentScenario: Scenario? = nil

open func title() -> String {
fatalError("Set feature title")
}
Expand All @@ -16,9 +16,23 @@ open class Feature: XCTestCase {

/// our lifecycle starts after xctest is ending
public override func tearDown() async throws {
try await run()
var errorFromRun: Error?
do {
try await run()
} catch {
errorFromRun = error
}
self.currentScenario = nil
try await super.tearDown()
var superTeardownError: Error?
do {
try await super.tearDown()
} catch {
superTeardownError = error
}

if let errorToThrow = errorFromRun ?? superTeardownError {
throw errorToThrow
}
}

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

func run() async throws {
// check if we have the scenario
if (currentScenario == nil) {
throw XCTSkip("""
To run the feature you have to setup the scenario for each test case.
Usage:
func testMyScenario() async throws {
scenario = Scenario("description")
.given // ...
let currentTestMethodName = self.name
if currentScenario == nil {
let rawMethodName = currentTestMethodName.split(separator: " ").last?.dropLast() ?? "yourTestMethod"

let errorMessage = """
‼️ SCENARIO NOT DEFINED in test method: \(currentTestMethodName)
Each 'func test...()' method within a 'Feature' class must assign a 'Scenario' to 'self.currentScenario'.

Example:
func \(rawMethodName)() async throws {
currentScenario = Scenario("A brief scenario description", file: #file, line: #line)
.given("some precondition")
.when("some action")
.then("some expected outcome")
}
""")
"""
throw ConfigurationError.missingScenario(errorMessage)
}

if (currentScenario!.disabled) {
throw XCTSkip("Scenario [\(currentScenario!.title)] is disabled")
if currentScenario!.disabled {
throw XCTSkip("Scenario '\(currentScenario!.name)' in test method \(currentTestMethodName) is disabled.")
}

try await TestConfiguration.setUpInstance()

if (currentScenario! is ParameterizedScenario) {
let parameterizedScenario = currentScenario! as! ParameterizedScenario
for scenario in parameterizedScenario.build() {
try await TestConfiguration.shared().run(self, scenario)
if let parameterizedScenario = currentScenario as? ParameterizedScenario {
for scenarioInstance in parameterizedScenario.build() {
scenarioInstance.feature = self
try await TestConfiguration.shared().run(self, scenarioInstance)
}
} else {
currentScenario?.feature = self
try await TestConfiguration.shared().run(self, currentScenario!)
}
}
Expand Down
10 changes: 5 additions & 5 deletions E2E/TestFramework/BDD/ParameterizedScenario.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import Foundation
import XCTest

public class ParameterizedScenario: Scenario {
public var parameters: [[String: String]] = [[:]]
public var table: [[String: String]] = [[:]]

public func parameters(_ parameters: [[String: String]]) -> Scenario {
self.parameters = parameters
public func table(_ table: [[String: String]]) -> Scenario {
self.table = table
return self
}

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

parameters.forEach { parameters in
let scenario = Scenario(replace(line: self.title, parameters: parameters))
table.forEach { parameters in
let scenario = Scenario(replace(line: self.name, parameters: parameters), parameters: parameters)
scenario.steps = self.steps.map { step in
let newStep = ConcreteStep()
newStep.context = step.context
Expand Down
13 changes: 7 additions & 6 deletions E2E/TestFramework/BDD/Scenario.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import XCTest

public class Scenario {
let id = UUID().uuidString
var title: String
var name: String
var steps: [ConcreteStep] = []
var pass: Bool = false
var error: Error? = nil
var disabled: Bool = false

var feature: Feature?
var parameters: [String: String]?

private var lastContext: String = ""

public init(_ title: String) {
self.title = title
public init(_ title: String, parameters: [String: String] = [:]) {
self.name = title
self.parameters = parameters
}

public func fail(file: StaticString?, line: UInt?, message: String) {
Expand Down
8 changes: 4 additions & 4 deletions E2E/TestFramework/Configuration/ITestConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

public protocol ITestConfiguration {
static var shared: () -> ITestConfiguration {get}
static func createInstance() -> ITestConfiguration

func run(_ feature: Feature, _ currentScenario: Scenario) async throws
static var shared: () -> TestConfiguration {get}
static func createInstance() -> TestConfiguration
func run(_ feature: Feature, _ currentScenario: Scenario?) async throws

/// setup
func setUp() async throws
Expand Down
Loading