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

Scenarios are running 2 times #88

Closed Tyler-Keith-Thompson closed 1 week ago

Tyler-Keith-Thompson commented 1 year ago
    Is there any reason, why should my scenarios run two times? I cannot find any settings for this. They even run two times when they are successful.

Originally posted by @SurglogsGithubUser in https://github.com/Tyler-Keith-Thompson/CucumberSwift/discussions/85

Tyler-Keith-Thompson commented 1 year ago

Relevant info: CocoaPods is the package manager. May be able to use the Cucumber Swift Sample repo to repro

Tyler-Keith-Thompson commented 1 year ago

Not able to repro: https://github.com/Tyler-Keith-Thompson/CucumberSwift/discussions/85#discussioncomment-5763839

Suspect that perhaps the new way we show tests from #72 is just confusing folks who use the test navigator rather than the report navigator.

MarekSlaninka commented 1 year ago

Hi, sadly no, they actually run two times. I will try to debug the code and find the reason why that is.

MarekSlaninka commented 1 year ago

Even override public class var defaultTestSuite: XCTestSuite in open class CucumberTest: XCTestCase is called two times. Do You have any idea, why that might be? Thank You

MarekSlaninka commented 1 year ago

Hi, I just want to remind myself with this issue. Do You have any idea why this might be?

Tyler-Keith-Thompson commented 1 year ago

Apologies, I haven't been able to repro and I haven't had much time to dedicate to this project. I expect things will ease up in a few weeks.

MarekSlaninka commented 1 year ago

Hi, I managed to check, if test is running for second time and stop it then.

open class CucumberTest: XCTestCase {
    static var didRun = false

    open override func invokeTest() {
        guard !Self.didRun else {return}
        Self.didRun = true
        super.invokeTest()
    }
 ...
Tyler-Keith-Thompson commented 1 year ago

I'm glad you have a workaround! It's very weird that that's necessary. This is actually quite insightful, because it means that XCTest is picking up on the entire test case twice, (as opposed to tests accidentally running themselves repeatedly, or something).

ianhlavats commented 3 months ago

Hi @Tyler-Keith-Thompson ,

Outstanding work on this project.

I ran into this issue as well and the following change seems to resolve it. I only see one invocation of my tests now, not two:

open class CucumberTest: XCTestCase {

    static var didRun = false

    static var didInitTestSuite = false

    override open func invokeTest() {
        guard !Self.didRun else { return }
        Self.didRun = true
        super.invokeTest()
    }

    override public class var defaultTestSuite: XCTestSuite {

        guard !Self.didInitTestSuite else { return XCTestSuite(name: "empty") }
        Self.didInitTestSuite = true

I'm happy to send a pull request and will do it soon.

ianhlavats commented 2 months ago

@Tyler-Keith-Thompson can you please review my PR #101 ?

ianhlavats commented 4 weeks ago

@Tyler-Keith-Thompson can we close this issue now?

MarekSlaninka commented 4 weeks ago

Yes, thank You