CucumberSwift icon indicating copy to clipboard operation
CucumberSwift copied to clipboard

Scenarios are running 2 times

Open Tyler-Keith-Thompson opened this issue 1 year ago • 10 comments

    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 avatar Apr 03 '23 16:04 Tyler-Keith-Thompson

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

Tyler-Keith-Thompson avatar Apr 03 '23 16:04 Tyler-Keith-Thompson

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.

Tyler-Keith-Thompson avatar Apr 29 '23 22:04 Tyler-Keith-Thompson

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

MarekSlaninka avatar May 02 '23 09:05 MarekSlaninka

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 avatar May 02 '23 13:05 MarekSlaninka

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

MarekSlaninka avatar Jun 13 '23 06:06 MarekSlaninka

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.

Tyler-Keith-Thompson avatar Jun 18 '23 16:06 Tyler-Keith-Thompson

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()
    }
 ...

MarekSlaninka avatar Jun 18 '23 16:06 MarekSlaninka

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).

Tyler-Keith-Thompson avatar Jun 18 '23 16:06 Tyler-Keith-Thompson

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 avatar Jun 16 '24 03:06 ianhlavats

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

ianhlavats avatar Jul 01 '24 10:07 ianhlavats

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

ianhlavats avatar Aug 17 '24 13:08 ianhlavats

Yes, thank You

MarekSlaninka avatar Aug 17 '24 14:08 MarekSlaninka