I am using EmbeddedSpecRunner to iteratively call tests from within a test . Though it runs successfully, I am not able to get each of the tests that were executed in the final Unroll. Only the parent test results are shown (Using a threadlocal to set each of the iterative itemized list for the next class to execute)
Parent class
class RiskSpecTabsTests()
@Unroll
def "executeTabsTests specName=#specName, tabName=#tabName"(String specName, String tabName) {
given:
when:
List<String> failures
CustomThreadLocalClass.setSpecTestProperty("currentTestTab", tabName)
CustomThreadLocalClass.setSpecTestProperty("specName", specName)
CustomThreadLocalClass.setSpecTestProperty("tables", [["WF_NEW_ADJ1"]
, ["WF_NEW_ADJ2"]]);
}
EmbeddedSpecRunner specRunner = new EmbeddedSpecRunner()
specRunner.throwFailure = false
result = specRunner.runClass(RiskSpecTabTablesTest)
failures = result.failures.collect { it.exception.getMessage() }
log.error(failures)
then:
verifyAll {
result.failures.size() == 0
}
where:`
[specName, tabName] << tabs`
#Second Class
class RiskSpecTabTablesTest (String table){
@Unroll
def "executeTests for table=#table" (String table) {
given:
EmbeddedSpecRunner specRunner = new EmbeddedSpecRunner();
specRunner.throwFailure = false
when:
log.info("Executing Test for table {}.", table)
CustomThreadLocalClass.setSpecTestProperty("currentTable", table)
TestExecutionSummary result = specRunner.runClass(RiskSpecTabTableTest)
then:
verifyAll {
result.failures.size() == 0
}
where:
[table] << CustomThreadLocalClass.getSpecTestProperty("tables")
}
#Third class RiskSpecTabTableTest
@Unroll
def "execute tab table testId=#testId " (Integer testId, String sample, Map<String, String> inputMap) {
given:
when:
def result = command.executeCommand(tableName, executionContext, new HashMap<>(), tabStep.resultType)
Object expectedResult = SpecTestTableHelper.getExpectedResultValue(inputMap)
then:
verifyAll() {
expectedResult == result
}
where:
[testId, sample, inputMap] << new RiskSingleTableTest(this, getSpecificationContext(),
CustomThreadLocalClass.getSpecTestProperty("specName"),
CustomThreadLocalClass.getSpecTestProperty("currentTestTab"),
CustomThreadLocalClass.getSpecTestProperty("currentTable"))
}
If I run each of the individual test classes (RiskSpecTabTablesTest , RiskSpecTabTableTest), I am able to see each of the tests being executed as a result of the parameters passed under the "where" . The same behavior for RiskSpecTabsTests (the main class)
Is there a way to propagate all the unrolled tests to the parent class, in order to be able to view the report for each of the individual tests executed under the parent class execution, and not only the parent class tests.?
I tried toggling throwFailure on the specRunner , unroll annotation on the different classes . I am able to see the failures of child classes in the parent class via
result.failures.collect { it.exception.getMessage() }
but how can I make it visible via the Spock reports.
Thanks!