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

编程入门 行业动态 更新时间:2024-10-08 12:33:51
本文介绍了如何使用 XCTest 在 Xcode 中测试 Swift 文件而无需构建整个应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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:

推荐答案

你应该试试 Swift Playground.

You should try a Swift Playground.

这是 developer.apple/swift 上的说明:

互动游乐场

Playgrounds 让编写 Swift 代码变得异常简单和有趣.输入一行代码,结果立即出现.如果您的代码随时间运行,例如通过循环,您可以在时间线助手中查看其进度.时间线以图形方式显示变量,在组成视图时绘制每个步骤,并且可以播放动画 SpriteKit 场景.当您在 Playground 中完善了您的代码后,只需将该代码移动到您的项目中即可.游乐场的一些用途包括:

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

尝试新的 API 以磨练您的 Swift 编码技能

Experiment with new APIs to hone your Swift coding skills

这篇关于如何使用 XCTest 在 Xcode 中测试 Swift 文件而无需构建整个应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 22:27:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1400893.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   应用程序   文件   测试   Xcode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!