Tyler-Keith-Thompson / CucumberSwift

A lightweight swift Cucumber implementation
https://tyler-keith-thompson.github.io/CucumberSwift/documentation/cucumberswift/
MIT License
74 stars 19 forks source link

Group steps per scenario in test report #72

Closed Hsilgos closed 1 year ago

Hsilgos commented 1 year ago

Hi again. May I ask if there is a reason why all steps are listed as plain list in test results? I tried the following:

public final class CucumberTest: XCTestCase {
    override public class var defaultTestSuite: XCTestSuite {
        ....
        // Instead of this:
        // allGeneratedTests.forEach { suite.addTest($0) }
        // Call this:
        generateAlltests(suite)
        return suite
    }

    static func generateAlltests(_ rootSuite: XCTestSuite) {
        for feature in Cucumber.shared.features.taggedElements(with: Cucumber.shared.environment, askImplementor: false) {
            let className = feature.title.toClassString() + readFeatureScenarioDelimiter()

            for scenario in feature.scenarios.taggedElements(with: Cucumber.shared.environment, askImplementor: true) {
                let childSuite = XCTestSuite(name: scenario.title.toClassString())
                var tests = [XCTestCase]()
                createTestCaseFor(className: className, scenario: scenario, tests: &tests)
                tests.forEach{ childSuite.addTest($0) }
                rootSuite.addTest(childSuite)
            }
        }
    }

And my test reports become much nicer, see screenshot. Does it make sense to continue to improve in this direction?

Screenshot 2023-02-02 at 23 07 56
Tyler-Keith-Thompson commented 1 year ago

That looks great! Feel free to submit a PR.

Tyler-Keith-Thompson commented 1 year ago

This is available in CucumberSwift v3.3.26