xcode - 如何使用 XCTest 在 Xcode 中测试 Swift 文件而无需构建整个应用程序?

标签 xcode unit-testing swift testing xctest

我想做的是在对文件进行微小更改后经常测试 Swift 文件。该文件可能包含一个或多个结构和类。

我不关心“应用程序”的概念,因为这纯粹是一种学术练习,用于练习我学到的一些新概念。我只想测试文件,不关心应用程序以及与应用程序相关的任何内容。

您可能会问为什么?速度。我希望它的测试速度非常快,现在最简单的例子需要几秒钟。我看到它在构建目标方面做了很多工作:

enter image description here

最佳答案

你应该试试 Swift Playground。

这是在 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

关于xcode - 如何使用 XCTest 在 Xcode 中测试 Swift 文件而无需构建整个应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28128169/

相关文章:

html - 调整大小后 UIWebView 加载/排序错误

python - 要修补哪个模块

unit-testing - 使用实时数据快速生成模拟存储库对象?起订量

ios - 如何使用 Realm Swift 保存值类型为 Measurement<UnitType> 的变量?

objective-c - 在 SQLite 语句中使用 NSArray

ios - UIScrollView 自动布局不工作 contentView 的宽度

iphone - Xcode 错误 : This device is no longer connected

ios - NSMutableArray ReplaceObjectAtIndex 崩溃

iphone - iOS 代码签名身份

unit-testing - 测试自定义 redux 中间件