Skip to content
Merged
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
59 changes: 56 additions & 3 deletions Tests/XCTestHTMLReportTests/CoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ final class CoreTests: XCTestCase {
// would-be pass into a failure. Asserting an exact split therefore
// measures simulator reliability rather than this project's
// behaviour. Assert only what the source actually determines.
XCTAssertEqual(all, 13, "One row per test method; fixed by the sample sources")
//
// 16 = 13 XCTest methods + 3 Swift Testing `@Test` functions in
// SwiftTestingSuite (SampleAppUnitTests target).
XCTAssertEqual(all, 16, "One row per test method; fixed by the sample sources")
XCTAssertEqual(
skipped,
1,
Expand All @@ -87,12 +90,62 @@ final class CoreTests: XCTestCase {
"Every remaining test lands in exactly one bucket"
)
XCTAssertGreaterThanOrEqual(
failed, 5,
"Five sample tests fail deliberately; a lower count means failures are being lost"
failed, 6,
"Six sample tests fail deliberately (including SwiftTestingSuite.intentionalFailure); " +
"a lower count means failures are being lost"
)
}
}

/// Swift Testing (`import Testing`, `@Test`) results are recorded
/// differently inside an `.xcresult` than plain XCTest results. This
/// asserts they still make it through the HTML pipeline: rendered at
/// all, with the right pass/fail status, and with the failure message
/// attached. See #393.
func testSwiftTestingResultsRendered() throws {
let testResultsUrl = try XCTUnwrap(testResultsUrl)
let summary = Summary(
resultPaths: [testResultsUrl.path],
renderingMode: .linking,
downsizeImagesEnabled: false,
downsizeScaleFactor: 0.5
)

let document = try SwiftSoup.parse(summary.html)

try XCTContext.runActivity(named: "Swift Testing results render like XCTest results") { _ in
let testCases = try document.select("div.test-summary")

func testCase(named name: String) throws -> Element {
try XCTUnwrap(
testCases.first {
let label = try? $0.select("p.list-item").first()?.text()
return label?.hasPrefix(name) == true
},
"No rendered test case found for Swift Testing test '\(name)'"
)
}

let passing = try testCase(named: "additionWorks()")
XCTAssertTrue(
passing.hasClass("succeeded"),
"additionWorks() is an unconditional #expect(true)"
)

let tagged = try testCase(named: "taggedMultiplication()")
XCTAssertTrue(
tagged.hasClass("succeeded"),
"taggedMultiplication() carries a .tags() trait but still passes"
)

let failing = try testCase(named: "intentionalFailure()")
XCTAssertTrue(failing.hasClass("failed"), "intentionalFailure() calls #expect(false)")

let failureText = try failing.select("div.activity-assertion-failure").text()
try XCTAssertContains(failureText, "This Swift Testing test intentionally fails")
}
}

func testRetryFunctionalityJunit() throws {
// Every test case in the fixture now yields one fewer `.unknown`
// result (an activity/log line) than these expectations were written
Expand Down
8 changes: 6 additions & 2 deletions XCTestHTMLReportSampleApp/SampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
F3AB01411F2459FA00334580 /* FirstSuite.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3AB01401F2459FA00334580 /* FirstSuite.swift */; };
F3BBACC41F2853570069962A /* iPhone.png in Resources */ = {isa = PBXBuildFile; fileRef = F3223CEF1F26341D00BEDA4A /* iPhone.png */; };
F3C1FC591FECE3C30028EC72 /* SampleAppUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3C1FC581FECE3C30028EC72 /* SampleAppUnitTests.swift */; };
5B67974379BD4801BE959C18 /* SwiftTestingSuite.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E9439014F9402F8D99C320 /* SwiftTestingSuite.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -56,6 +57,7 @@
F3C1FC561FECE3C30028EC72 /* SampleAppUnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SampleAppUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F3C1FC581FECE3C30028EC72 /* SampleAppUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleAppUnitTests.swift; sourceTree = "<group>"; };
F3C1FC5A1FECE3C30028EC72 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
38E9439014F9402F8D99C320 /* SwiftTestingSuite.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftTestingSuite.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -134,6 +136,7 @@
isa = PBXGroup;
children = (
F3C1FC581FECE3C30028EC72 /* SampleAppUnitTests.swift */,
38E9439014F9402F8D99C320 /* SwiftTestingSuite.swift */,
F3C1FC5A1FECE3C30028EC72 /* Info.plist */,
);
path = SampleAppUnitTests;
Expand Down Expand Up @@ -296,6 +299,7 @@
buildActionMask = 2147483647;
files = (
F3C1FC591FECE3C30028EC72 /* SampleAppUnitTests.swift in Sources */,
5B67974379BD4801BE959C18 /* SwiftTestingSuite.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -512,7 +516,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = XK98WVAH5W;
INFOPLIST_FILE = SampleAppUnitTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tito.XCTestHTMLReportSampleAppUnitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -529,7 +533,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = XK98WVAH5W;
INFOPLIST_FILE = SampleAppUnitTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tito.XCTestHTMLReportSampleAppUnitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// SwiftTestingSuite.swift
// SampleAppUnitTests
//
// Added to investigate XCTestHTMLReport's support for Swift Testing
// results (`import Testing`) as part of #393.
//

import Testing

struct SwiftTestingSuite {
@Test func additionWorks() {
#expect(1 + 1 == 2)
}

@Test func intentionalFailure() {
#expect(false, "This Swift Testing test intentionally fails")
}

@Test("Tagged multiplication check", .tags(.sampleTag))
func taggedMultiplication() {
#expect(2 * 3 == 6)
}
}

extension Tag {
@Tag static var sampleTag: Tag
}
Loading