Spike: Aggregate device failures into a new section called 'All results' which shows all tests across all devices by amleszk · Pull Request #116 · XCTestHTMLReport/XCTestHTMLReport · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions XCTestHTMLReport/XCTestHTMLReport.xcodeproj/project.pbxproj
11 changes: 11 additions & 0 deletions XCTestHTMLReport/XCTestHTMLReport/Classes/HTMLTemplates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,17 @@ struct HTMLTemplates
<div id=\"container\">
<div id=\"left-sidebar\" class=\"sidebar\">
<div class=\"resizer\"></div>
<h4 id=\"device-header\">All tests</h4>
<ul id=\"info-sections\">
<li class=\"section\">
<ul class=\"device-info\" onclick=\"selectDevice('ALL', this);\">
<li><span class=\"device-result icon left failure\"></span><h3 class=\"device-name\">All devices</h3></li>
<li class=\"device-os\">Device OS</li>
<li class=\"device-model\">Device Model</li>
<li class=\"device-identifier\">Device Identifier</li>
</ul>
</li>
</ul>
<h4 id=\"device-header\">Devices</h4>
<ul id=\"info-sections\">
<li class=\"section\">
Expand Down
109 changes: 109 additions & 0 deletions XCTestHTMLReport/XCTestHTMLReport/Classes/Models/JoinedRuns.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// JoinedRuns.swift
// XCTestHTMLReport
//
// Created by Alistair Leszkiewicz on 11/30/18.
// Copyright © 2018 Tito. All rights reserved.
//

import Foundation

// Represents a series of test runs joined together into a single
// success / failure run
struct JoinedRuns : HTML
{
let runs: [Run]

init(runs: [Run]) {
self.runs = runs
}

var htmlTemplate = HTMLTemplates.run

var numberOfTests : Int {
return runs.map { $0.numberOfTests }.sum()
}

var numberOfPassedTests : Int {
return runs.map { $0.numberOfPassedTests }.sum()
}

var numberOfFailedTests : Int {
return runs.map { $0.numberOfFailedTests }.sum()
}

var testSummaries: [TestSummary] {
return runs.flatMap { $0.testSummaries }
}

var htmlPlaceholderValues: [String: String] {
return [
"DEVICE_IDENTIFIER": "ALL",
"N_OF_TESTS": String(numberOfTests),
"N_OF_PASSED_TESTS": String(numberOfPassedTests),
"N_OF_FAILED_TESTS": String(numberOfFailedTests),
"TEST_SUMMARIES": testSummaries.map { $0.prefixUUIDForJoinedRunWithChildren() }.map { $0.html }.joined()
]
}
}


private extension Array where Element == Int {

func sum() -> Int {
return reduce(0, +)
}

}

/// To keep these UUID's unique within the HTML document
/// they are all pre-pended with the constant string 'ALL'
fileprivate protocol JoinedTestSummaryDisplayProtocol {
var uuid: String { get set }
func prefixUUIDForJoinedRun() -> Self
func prefixUUIDForJoinedRunWithChildren() -> Self
}

fileprivate extension JoinedTestSummaryDisplayProtocol {

func prefixUUIDForJoinedRun() -> Self {
var copy = self
copy.uuid = "ALL-" + copy.uuid
return copy
}

func prefixUUIDForJoinedRunWithChildren() -> Self {
return prefixUUIDForJoinedRun()
}
}

extension TestSummary: JoinedTestSummaryDisplayProtocol {

func prefixUUIDForJoinedRunWithChildren() -> TestSummary {
var copy = self.prefixUUIDForJoinedRun()
copy.tests = copy.tests.map { $0.prefixUUIDForJoinedRunWithChildren() }
return copy
}

}

extension Test: JoinedTestSummaryDisplayProtocol {

func prefixUUIDForJoinedRunWithChildren() -> Test {
var copy = self.prefixUUIDForJoinedRun()
copy.subTests = copy.subTests?.map { $0.prefixUUIDForJoinedRunWithChildren() }
copy.activities = copy.activities?.map { $0.prefixUUIDForJoinedRunWithChildren() }
return copy
}

}
extension Activity: JoinedTestSummaryDisplayProtocol {

func prefixUUIDForJoinedRunWithChildren() -> Activity {
var copy = self.prefixUUIDForJoinedRun()
copy.subActivities = copy.subActivities?.map { $0.prefixUUIDForJoinedRunWithChildren() }
return copy
}


}
1 change: 1 addition & 0 deletions XCTestHTMLReport/XCTestHTMLReport/Classes/Models/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation

/// Represents a single test run against a single test device
struct Run: HTML
{
private let activityLogsFilename = "action.xcactivitylog"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private extension Status {
}
}

/// Represents single test device attributes
struct RunDestination : HTML
{
var name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension Summary: HTML
"RESULT_CLASS": runs.reduce(true, { (accumulator: Bool, run: Run) -> Bool in
return accumulator && run.status == .success
}) ? "success" : "failure",
"RUNS": runs.map { $0.html }.joined()
"RUNS": JoinedRuns(runs: runs).html + runs.map { $0.html }.joined()
]
}
}
Expand Down
11 changes: 11 additions & 0 deletions XCTestHTMLReport/XCTestHTMLReport/HTML/index.html