How can I test Swift files in Xcode using XCTest without having to build the entire app?

只谈情不闲聊 提交于 2019-12-12 20:15:29

问题


What I'm trying to do is test a Swift file frequently after making tiny changes to the file. The file may contain one or more structs and classes.

I don't care about a concept of an "app" because this is purely an academic exercise to practice some new concepts I've learned. I just want to test the file and don't care about the app and anything related to the app.

You may be asking why? Speed. I want it to be really fast to test, right now it takes a few seconds for the most trivial example. I see it does a lot of work to build the targets:


回答1:


You should try a Swift Playground.

Here is the description at developer.apple.com/swift:

Interactive Playgrounds

Playgrounds make writing Swift code incredibly simple and fun. Type a line of code and the result appears immediately. If your code runs over time, for instance through a loop, you can watch its progress in the timeline assistant. The timeline displays variables in a graph, draws each step when composing a view, and can play an animated SpriteKit scene. When you’ve perfected your code in the playground, simply move that code into your project. Some uses for playgrounds include:

  • Design a new algorithm, watching its results every step of the way

  • Create new tests, verifying they work before promoting into your test suite

  • Experiment with new APIs to hone your Swift coding skills



来源:https://stackoverflow.com/questions/28128169/how-can-i-test-swift-files-in-xcode-using-xctest-without-having-to-build-the-ent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!