XCTest Doesn't Work With Protocol Extensions
| Originator: | stephen | ||
| Number: | rdar://23465272 | Date Originated: | 2015-11-09 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | 7.1 |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
Note: I'm really reopening 22960120. I thought the provided solution might work, but I don't think it does.
---
I have a protocol and multiple implementations of that protocol. I'd be great to have a way to specify a protocol for the testing itself, along with a protocol extension with the common tests.
This means I could have:
protocol CommonTests {
var testObject: SomeProtocol!
func testA()
func testB()
}
extension CommonTests {
func testA() { ... }
func testB() { ... }
}
class SomeClassATests: XCTestCase, CommonTests {
var testObject: SomeProtocol!
override func setUp() {
super.setUp()
testObject = SomeClassA()
}
}
class SomeClassBTests: XCTestCase, CommonTests {
var testObject: SomeProtocol!
override func setUp() {
super.setUp()
testObject = SomeClassB()
}
}
---
The original solution was to create a common subclass that could test both, but this confuses the relationship. A common subclass cannot exist because these are protocols, so the common subclass would need to have some sort of implementation of testObject for that to work. SomeClassATests could be the base class, but this seems to just confusion the relationship.
Steps to Reproduce:
Expected Results:
Tests are run for test case and the results would show up in the test navigator.
Actual Results:
Doing this currently shows no tests in the test navigator and none of the code in the test protocol extensions is run.
Version:
Xcode 7.1(7B91b) / Mac OS X 10.11.1 (15B42)
Notes:
Configuration:
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!