Report describe/it inside XCTestCases using XCTest #32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While reviewing #30, I had some alternative ideas that I wanted to test out. This is a simpler approach that adds a
describe
andit
methods toXCTestCase
via an extension, and immediately runs those closures and reports failures directly to XCTest.This explicitly disallows use of the global context an thus if you try to use the global
describe
orit
during an XCTest invocation a fatalError will be raised.Example tests and report:
Ideas for future extension
It would be nice to be able to inject the full test hierarchy into XCTest along with the skipped tests.
This will allow proper test reporting for
describe
andcontext
inside Xcode output. Interacting with XCTest run-time is limited and I did not find a way to do this directly to XCTest.I have in the past done this via injecting
NSInvocation
s to the test invocation list for a class, which would allow reporting each invocations separately. Unfortunately NSInvocation is not permitted in Swift (In Swift 2 I did find some measures to be able to do this (https://github.com/kylef/JSONSchema.swift/blob/0.2.0/JSONSchemaTests/JSONSchemaCases.swift#L63-L81) but that was broken in Swift 3).This could be possible by including Objective-C sources, however that is problematic with Xcode projects generated with
swift package generate-xcodeproj
. You cannot link against the XCTest framework from Objective-C via swift pm (swiftlang/swift-package-manager#1422 would allow this in the future).Closes #2