Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report describe/it inside XCTestCases using XCTest #32

Merged
merged 1 commit into from
Feb 6, 2018

Conversation

kylef
Copy link
Owner

@kylef kylef commented Dec 27, 2017

While reviewing #30, I had some alternative ideas that I wanted to test out. This is a simpler approach that adds a describe and it methods to XCTestCase 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 or it during an XCTest invocation a fatalError will be raised.

Example tests and report:

messages image 2733122485

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 and context 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 NSInvocations 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

@ilyapuchka ilyapuchka mentioned this pull request Dec 27, 2017
@kylef kylef merged commit a116c2c into master Feb 6, 2018
@kylef kylef deleted the kylef/xcode-reporter branch February 6, 2018 18:58
@yonaskolb
Copy link

I'm getting an issue with this when running in Xcode, in that there is always an alert after running the tests.
Running swift test is fine however.

screen shot 2018-07-22 at 11 28 28 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants