Xcode 中的测试 类 是什么?
What is test classes in Xcode?
我来自不习惯或不熟悉的 IT 教育背景和文化 "test driven development"。长话短说,我在目前的工作中学习了 Xcode 编程,在抑制了对每次创建新项目时不断出现的 "test" 和 "UI test" 文件的好奇心几个月后,我决定现在我有时间去寻找它。那是我学习单词 "test driven development" 的地方。
但令人惊讶的是,对于想要学习测试驱动开发基本概念的新手来说,那里的文章太少了,更不用说在 Xcode 中了解如何去做了。我能找到的文章都是高级资料,假设 reader 已经熟悉 TDD。我在堆栈溢出中发现的唯一解释 TDD 基础知识的 QA 是 here, and that is not enough explanation because it only explain a very brief of what, not how. And also, it itself is tagged as duplicate to a QA link that's already removed from stack overflow. And the Apple's own documentation about writing test classes 也假设我已经熟悉这个概念。
有人可以举一个非常简单的例子来说明 TDD 如何在编写 Xcode 项目中工作,尤其是在 Swift iOS 中吗?比如,我的应用程序代码是什么,我的测试代码是什么,以及两者是如何连接或相关的。我的意思是,我真的不明白在测试 类 上编写测试代码如何帮助您 "debugging" 您的主要代码的概念。
因为根据我对 "testing" 的解释,测试代码必须 "simulate" 用户如何在 UI 上输入数据、尝试所有可能的输入组合等。而且, "test" 和 "UI test" 之间有什么区别?代码如何测试 UI?哦,如果您想将此问题标记为 "duplicate",请同时将 link 指定到重复项所在的位置。谢谢
Test Driven Development, or TDD for short, is a simple software
development practice where unit tests, small focused test cases, drive
the development forward. This is most easily explained by the Three
Rules of TDD that dictate the following:
You are not allowed to write any production code unless it is to make
a failing unit test pass. You are not allowed to write any more of a
unit test than is sufficient to fail; and compilation failures are
failures. You are not allowed to write any more production code than
is sufficient to pass the one failing unit test. That means that test
cases are written before any production code. Not all tests are
written up front, it’s rather that a small test is written, then a
small piece of production code is written that only allows that test
to pass. This is repeated in many small iterations: test, fail, code,
pass, test, fail, code, pass…
Many people consider TDD to encourage clean code, simple architectures
and a stable system that’s actually testable. Plus, it’s also fun!
We’ve previously written about various aspects of TDD, but in this
tutorial we’ll focus on how it works for XCode projects, where you
write apps for Mac and iPhone. We will create a simple XCode project,
do some special configuration steps and then demonstrate how TDD can
be used to write your app. We’re going to use OCUnit and its framework
SenTestingKit, which nowadays is included with Apple’s XCode tools.
查看 this 文章,该文章解释了 XCode 中测试驱动开发的工作原理。
我来自不习惯或不熟悉的 IT 教育背景和文化 "test driven development"。长话短说,我在目前的工作中学习了 Xcode 编程,在抑制了对每次创建新项目时不断出现的 "test" 和 "UI test" 文件的好奇心几个月后,我决定现在我有时间去寻找它。那是我学习单词 "test driven development" 的地方。
但令人惊讶的是,对于想要学习测试驱动开发基本概念的新手来说,那里的文章太少了,更不用说在 Xcode 中了解如何去做了。我能找到的文章都是高级资料,假设 reader 已经熟悉 TDD。我在堆栈溢出中发现的唯一解释 TDD 基础知识的 QA 是 here, and that is not enough explanation because it only explain a very brief of what, not how. And also, it itself is tagged as duplicate to a QA link that's already removed from stack overflow. And the Apple's own documentation about writing test classes 也假设我已经熟悉这个概念。
有人可以举一个非常简单的例子来说明 TDD 如何在编写 Xcode 项目中工作,尤其是在 Swift iOS 中吗?比如,我的应用程序代码是什么,我的测试代码是什么,以及两者是如何连接或相关的。我的意思是,我真的不明白在测试 类 上编写测试代码如何帮助您 "debugging" 您的主要代码的概念。
因为根据我对 "testing" 的解释,测试代码必须 "simulate" 用户如何在 UI 上输入数据、尝试所有可能的输入组合等。而且, "test" 和 "UI test" 之间有什么区别?代码如何测试 UI?哦,如果您想将此问题标记为 "duplicate",请同时将 link 指定到重复项所在的位置。谢谢
Test Driven Development, or TDD for short, is a simple software development practice where unit tests, small focused test cases, drive the development forward. This is most easily explained by the Three Rules of TDD that dictate the following:
You are not allowed to write any production code unless it is to make a failing unit test pass. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures. You are not allowed to write any more production code than is sufficient to pass the one failing unit test. That means that test cases are written before any production code. Not all tests are written up front, it’s rather that a small test is written, then a small piece of production code is written that only allows that test to pass. This is repeated in many small iterations: test, fail, code, pass, test, fail, code, pass…
Many people consider TDD to encourage clean code, simple architectures and a stable system that’s actually testable. Plus, it’s also fun! We’ve previously written about various aspects of TDD, but in this tutorial we’ll focus on how it works for XCode projects, where you write apps for Mac and iPhone. We will create a simple XCode project, do some special configuration steps and then demonstrate how TDD can be used to write your app. We’re going to use OCUnit and its framework SenTestingKit, which nowadays is included with Apple’s XCode tools.
查看 this 文章,该文章解释了 XCode 中测试驱动开发的工作原理。