Suppose you have hierarchical data and want to get the combined value of individual properties, what is the most elegant or groovy way to do this?
The following example contains information about failed and missed tests. Of course, it makes sense that these values are separated, but to use a list of all the tests that did not succeed, I came across two possible solutions that both of them did not satisfy me.
def junitResultList = [
[
name: "Testsuite A",
children: [
failedTests: ["Test 1", "Test 2"],
skippedTests: []
]
],
[
name: "Testsuite B",
children: [
failedTests: ["CursorTest"],
skippedTests: ["ClickTest", "DragNDropTest"]
]
]
]
To be more specific, I want the value to be ["Test 1", "Test 2", "CursorTest", "ClickTest", "DragNDropTest"].
The first approach was to simply add a list of test extensions:
(junitResultList*.children*.failedTests +
junitResultList*.children*.skippedTests).flatten()
, , groovy , , - :
(junitResultList*.children*.findAll {
['skippedTests', 'failedTests'].contains(it.key)
})*.values().flatten()