Xcode unit testing should support Behaviour-Driven Development workflows

Originator:ash
Number:rdar://34875753 Date Originated:8/10/2017
Status:Closed as dupe (12269848) Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:
 
Right now, the Xcode unit testing capabilities are limited to subclassing `XCTestCase` and overriding two methods: `setUp` and `tearDown`. This is a really limited workflow because it constrains the expressibility of our unit tests. Here's an example from the open source testing framework Quick:

var db: DataBase!

beforeEach {
    db = DataBase.testDataBase()
}

afterEach {
    db.destroy()
}

it("adds new rows to the db") {
}

describe("prepopulated") {
    beforeEach {
        db.populateWithFakeData()
    }

    it("can fetch rows from the db") {
    }
}

Nesting contexts within each other has fundamentally changed the way I write unit tests, and is fairly standard in the Ruby and JavaScript testing communities. There are libraries like Quick, available at https://github.com/Quick/Quick , but it's up to the developer to know about Quick, to download it, install with CocoaPods or Carthage, and integrate with it. That's a lot of work, and many developers don't bother, so their tests suffer or they just don't write any.

And Quick is limited because it can only integrate with XCTest, so all tests need an additional `import` and have to be done in a specific overridden function:

import Quick
class MySpec: QuickSpec {
  override func spec() {
    // tests go here
  }
}

That's two levels of indentation before I've even written a test! I want to be able to write tests in the top level of the test file.

Xcode is in a unique position to be able to do things like transform or inject code into test files before it gets compiled or run – it wouldn't be easy to make a BDD workflow supported in Xcode, but I know Apple is up to the challenge. I just want to write modern tests with the tools that Apple provides.

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!