net-a-porter-mobile / XCTest-Gherkin

Gherkin syntax for XCTestCase
Apache License 2.0
254 stars 64 forks source link

Feature request - Implement custom versions of 'test000, test001, etc.' #181

Open tomleightonstars opened 3 years ago

tomleightonstars commented 3 years ago

Hi, me again! I hope you're well!

I'm just wondering if there's a way to implement a custom version of the SelectorString value in NativeScenario.swift? I'm aware I can change the value in there but then it won't be iterated through git to others.

I know similar is done when parsing the location of the Features folder, so maybe something similar could be done?

I can see 'test' is required in the returned name for the tests to actually run, it would be great to then be able to have something custom after that, if anything, e.g.: testAScenarioName test_AScenarioName test-AScenarioName

❤️

bbe02 commented 3 years ago

Thanks @tomleightonstars raising this. It will be a great help if we can do the above.

deanWombourne commented 3 years ago

Hey.

Couple of question to see if I've understood your requirements :)

  1. Do you want to replace the 001, 002 etc i.e. test001TestAFunnyThing could become testHELLOTestAFunnyThing?
  2. Do you want to replace / insert a fixed string, or would you want to insert a string based on information about the test i.e. the index, the name etc?
tomleightonstars commented 3 years ago
  1. Yes exactly that
  2. Just a fixed string would be perfect for me, although I could see maybe FeatureName being useful to others

Thank you for all your hard work with this repo 😄❤️

tomleightonstars commented 3 years ago

Or, would it even possible to remove 'test' as well?

kerrmarin commented 3 years ago

IIRC we added the numbers to make sure that tests were run sequentially as defined, because the order wasn't guaranteed when the tests were dynamic...?

bbe02 commented 3 years ago

I would be against the idea of running tests in some order as each test should be independent. The test name should be unique and should not contain static prefixes.

deanWombourne commented 3 years ago

Personally, so would I. However, a guiding principle I've been following is "do what cucumber would do" and (I believe) it will run the tests in the order they are specified in the feature file.

That being said, if people want to opt out of that behaviour then that's fine by me :)

My current plan for this is for a user to be able to pass in a block which will return the test selector name - where the default would be this (backwards compatibility is important):

NativeScenario.selectorFactory = { (name: String, index: Int) -> String in
  "\(self.leftPad(index))\(self.name.camelCaseify)"
}

This isn't final - there's probably some tweaking here.

deanWombourne commented 3 years ago

FYI @tomleightonstars The prefix test is what Xcode uses to determine which methods are tests - without it they don't get run.

tomleightonstars commented 3 years ago

Personally, so would I. However, a guiding principle I've been following is "do what cucumber would do" and (I believe) it will run the tests in the order they are specified in the feature file.

That being said, if people want to opt out of that behaviour then that's fine by me :)

My current plan for this is for a user to be able to pass in a block which will return the test selector name - where the default would be this (backwards compatibility is important):

NativeScenario.selectorFactory = { (name: String, index: Int) -> String in
  "\(self.leftPad(index))\(self.name.camelCaseify)"
}

This isn't final - there's probably some tweaking here.

That sounds like a great plan! I had a go at trying to add something in but I couldn't get it working 🤦‍♂️

FYI @tomleightonstars The prefix test is what Xcode uses to determine which methods are tests - without it they don't get run.

fair enough! I thought that might be the case