-
Notifications
You must be signed in to change notification settings - Fork 51
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 indexes to test names so that Specmatic always generates tests with unique names. #1082
Changes from 3 commits
afd8063
5239dd7
4cb8d40
3f276bd
8f13d7c
b5db049
93d1ade
c079382
3aa0303
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -352,8 +352,8 @@ data class Feature( | |
flagsBased | ||
else | ||
flagsBased.withoutGenerativeTests() | ||
|
||
originalScenario.generateTestScenarios(resolverStrategies, testVariables, testBaseURLs).map { Pair(originalScenario.copy(generativePrefix = flagsBased.positivePrefix), it) } | ||
val testScenarios = originalScenario.generateTestScenarios(resolverStrategies, testVariables, testBaseURLs) | ||
addIndexes(originalScenario, testScenarios, flagsBased.positivePrefix) | ||
} | ||
|
||
fun negativeTestScenarios(): Sequence<Pair<Scenario, ReturnValue<Scenario>>> { | ||
|
@@ -365,19 +365,13 @@ data class Feature( | |
val negativeTestScenarios = | ||
negativeScenario.generateTestScenarios(flagsBased, testVariables, testBaseURLs) | ||
|
||
negativeTestScenarios.filterNot { negativeTestScenarioR -> | ||
val filtered = negativeTestScenarios.filterNot { negativeTestScenarioR -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I understand why we are naming this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
negativeTestScenarioR.withDefault(false) { negativeTestScenario -> | ||
val sampleRequest = negativeTestScenario.httpRequestPattern.generate(negativeTestScenario.resolver) | ||
originalScenario.httpRequestPattern.matches(sampleRequest, originalScenario.resolver).isSuccess() | ||
} | ||
}.mapIndexed { index, negativeTestScenarioR -> | ||
Pair(negativeScenario, negativeTestScenarioR.ifValue { negativeTestScenario -> | ||
negativeTestScenario.copy( | ||
generativePrefix = flagsBased.negativePrefix, | ||
disambiguate = { "[${(index + 1)}] " } | ||
) | ||
}) | ||
} | ||
addIndexes(negativeScenario, filtered, flagsBased.negativePrefix) | ||
} | ||
} | ||
|
||
|
@@ -400,6 +394,27 @@ data class Feature( | |
serverState = emptyMap() | ||
} | ||
|
||
private fun addIndexes( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically this method is adding both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will also be super helpful to unit test this method separately. While the feature level tests are very useful, this will allow is try all difficult combinations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this method doing too much, should we separate out application of prefix and index as two separate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ToDo's
|
||
originalScenario: Scenario, | ||
testScenarios: Sequence<ReturnValue<Scenario>>, | ||
prefix: String | ||
): Sequence<Pair<Scenario, ReturnValue<Scenario>>> { | ||
val sequenceHasZeroOrOne = testScenarios.take(2).count() < 2 | ||
|
||
return testScenarios.mapIndexed { index, positiveTestScenarioR -> | ||
val indexLabel: () -> String = if (sequenceHasZeroOrOne) { | ||
{ "" } | ||
} else { | ||
{ "[${(index + 1)}] " } | ||
} | ||
Pair( | ||
originalScenario.addIndexLabelAndPrefix(prefix, indexLabel), | ||
positiveTestScenarioR.ifValue { scenario -> | ||
scenario.addIndexLabelAndPrefix( prefix, indexLabel) | ||
}) | ||
} | ||
} | ||
|
||
private fun combine(baseScenario: Scenario, newScenario: Scenario): Scenario { | ||
return convergeURLMatcher(baseScenario, newScenario).let { convergedScenario -> | ||
convergeHeaders(convergedScenario, newScenario) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please rename
filtered
to what it actually contains? This will help readability of line wherefiltered
is being used?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: Renamed the variable in negativeTestScenarios fun to more descriptive…