Skip to content
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

Add running by tag & ignoring based on tag #185

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8b23f8e
remove numbering of scenario names
tomleightonstars Mar 18, 2021
4ee0b7b
Merge pull request #1 from tomleightonstars/RemoveTestNumbering
tomleightonstars Mar 18, 2021
63150ee
Fixed package
Apr 7, 2021
b2d8db6
Add tag parsing. Update readme.
tomleightonstars Apr 19, 2021
62e6990
Merge pull request #2 from tomleightonstars/tagsParse
tomleightonstars Apr 21, 2021
0c37e41
Add tag parsing. Update readme.
tomleightonstars Mar 18, 2021
1fd2b2c
fix outline scenarios
tomleightonstars Apr 26, 2021
e403b45
change for multi column example tables
tomleightonstars Apr 27, 2021
05486da
Merge pull request #3 from tomleightonstars/ExampleScenarioFix
tomleightonstars Apr 27, 2021
8d5b04b
Outline scens with same name are fine
tomleightonstars Apr 27, 2021
596627e
outline - changes for if the name has already been changed
tomleightonstars Apr 28, 2021
6b6b4b8
Uncamelcasing the names of tests
tomleightonstars Jun 9, 2021
cc5707e
Merge pull request #4 from tomleightonstars/uncamelcase_test_names
tomleightonstars Jun 9, 2021
a7599a6
Add tag ignoring
tomleightonstars Jun 22, 2021
4966f44
Add tag ignoring functionality
tomleightonstars Jun 22, 2021
3e32983
Update README.md
tomleightonstars Jun 22, 2021
f0c92a1
Update README.md
tomleightonstars Jun 22, 2021
3dcbda2
Update NativeFeatureParser.swift
tomleightonstars Jun 22, 2021
21a389b
Merge pull request #5 from tomleightonstars/TagIgnoring
tomleightonstars Jun 22, 2021
cd8310b
added default tags
Jun 30, 2021
bc0fee9
Revert "added default tags"
Jun 30, 2021
572d04e
Adding include/ignore functionality by default
tomleightonstars Jul 1, 2021
b010045
whitespaces
tomleightonstars Jul 1, 2021
7e03f51
ignore if scenario has both ignore and include
tomleightonstars Jul 1, 2021
8af53b8
tweak
tomleightonstars Jul 1, 2021
3183459
add missing bracket
tomleightonstars Jul 1, 2021
a50f942
implement ignore tag default
tomleightonstars Jul 21, 2021
7a389be
update ignore line
tomleightonstars Jul 21, 2021
254b9aa
adding nice message if no scenarios are outputted
tomleightonstars Jul 21, 2021
a55e456
Merge branch 'addIgnoreTagDefault' of https://github.com/tomleightons…
tomleightonstars Jul 22, 2021
37940ac
Merge branch 'tagsParse-commitToMain' of https://github.com/tomleight…
tomleightonstars Jul 22, 2021
dab11e7
Tags checking moved
tomleightonstars Jul 22, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Feature: Feature file parsing
Given I have a working Gherkin environment
Then This test should not fail

@iOS1
@iOS1 @iOS6 @iOS7
Scenario: Nested steps
Given This step should call another step
Then This test should not fail
Expand Down
19 changes: 17 additions & 2 deletions Pod/Native/NativeFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
class NativeFeature: CustomStringConvertible {
let name: String
let featureDescription: String
let scenarios: [NativeScenario]
var scenarios: [NativeScenario]
let background: NativeBackground?

required init(name: String, description: String, scenarios: [NativeScenario], background: NativeBackground?) {
Expand Down Expand Up @@ -62,6 +62,7 @@ extension NativeFeature {
var background: NativeBackground?
var featureDescription: [String]?
var scenarioTags: [String] = []
var featureTags: [String] = []

func saveBackgroundOrScenarioAndUpdateParseState(_ lineSuffix: String){
let description = state.description.joined(separator: "\n")
Expand All @@ -83,10 +84,20 @@ extension NativeFeature {

// Filter comments (#) and tags (@), also filter white lines
guard line.first != "#" && !line.isEmpty else { continue }

// Adds Feature tags to each Scenario within the Feature
if !featureTags.isEmpty && !scenarioTags.contains(where: featureTags.contains) {
scenarioTags.append(contentsOf: featureTags)
}

if line.first == "@" {
scenarioTags.append(String(line.dropFirst()))
let tags = String(line).replacingOccurrences(of: "@", with: "")
.components(separatedBy: " ")
.filter{ !$0.isEmpty }
scenarioTags.append(contentsOf: tags)
continue
}

if let (linePrefix, lineSuffix) = line.lineComponents() {
switch linePrefix {
case Language.current.keywords.Background:
Expand All @@ -107,6 +118,10 @@ extension NativeFeature {
case Language.current.keywords.ExampleLine:
state.exampleLines.append((lineIndex+1, lineSuffix))
case Language.current.keywords.Feature:
// Gets all Feature tags
if !scenarioTags.isEmpty {
featureTags = scenarioTags
}
scenarioTags = []
default:
break
Expand Down
35 changes: 34 additions & 1 deletion Pod/Native/NativeTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,40 @@ open class NativeTestCase: XCGNativeInitializer {
assertionFailure("Could not retrieve features from the path '\(path)'")
return []
}


var userIgnoreTags: [String] = []
if let userIgnoreTagsArgumentIndex = CommandLine.arguments.firstIndex(where: { $0.hasPrefix("IgnoreTags=") }) {
userIgnoreTags = CommandLine.arguments[userIgnoreTagsArgumentIndex].replacingOccurrences(of: "IgnoreTags=", with: "")
.replacingOccurrences(of: "@", with: "")
.components(separatedBy: ",")
.filter{ !$0.isEmpty }
}
userIgnoreTags.append("ignore")

var userTags: [String] = []
if let userTagsArgumentIndex = CommandLine.arguments.firstIndex(where: { $0.hasPrefix("Tags=") }) {
userTags = CommandLine.arguments[userTagsArgumentIndex].replacingOccurrences(of: "Tags=", with: "")
.replacingOccurrences(of: "@", with: "")
.components(separatedBy: ",")
.filter{ !$0.isEmpty }
}

var remainingScenarioCount = 0
for feature in features {
for index in (0...feature.scenarios.count-1).reversed() {
if (feature.scenarios[index].tags.contains(where: userIgnoreTags.contains)) ||
(!userTags.isEmpty && !feature.scenarios[index].tags.contains(where: userTags.contains)) {
feature.scenarios.remove(at: index)
} else {
remainingScenarioCount+=1
}
}
}

if remainingScenarioCount == 0 {
print("There aren't any scenarios to run. Maybe you need to check the tags you're using?")
}

return features
}

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,26 @@ There is an example of this in the Example/ project as part of this pod. Look at

The advantages of this are obvious; you get to quickly run your existing feature files and can get up and running quickly. The disadvanages are beacuse the tests are generated at runtime they can't be run individually from inside Xcode so debugging is tricker. I would use this to start testing inside Xcode but if it gets hairy, convert that feature file into a native Swift test and debug from there.

### Running using tags

You can use tags to run or ignore a subsection of your tests. These can be at Feature level, or on individual Scenarios. Tags must start with "@" and must not contain any spaces.

For Feature level tags, ensure these are before your Feature name declaration in your feature file.
For Scenario level tags, ensure these are before your Scenario name declaration in your feature file.
There can be multiple on a single line, or individual tags on individual lines.

To run using the tags:
#### CLI:
For tag ignoring, append `-IgnoreTags=@tagName1,@tagName2` to your CLI command, swapping out @tagName1/2 for your tag names.
For tag inclusion, append `-Tags=@tagName1,@tagName2` to your CLI command, swapping out @tagName1/2 for your tag names.

#### Test Plan:
Within Xcode
1. Go to edit your test plan
1. Select the 'Configurations' tab
1. Open the 'Arguments' section
1. For the 'Arguments Passed On Launch' field, enter the value 'Tags=@tagName1,@tagName2', replacing '@tagName1,@tagName2' with your tag names, or '-IgnoreTags=@tagName1,@tagName2' for tag ignoring
1. Now run your tests in the UI using your Test Plan

### Localisation of feature files

Expand Down