xcode 应用测试 VS 逻辑测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6730960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Application Tests VS Logic Tests
提问by nduplessis
Since application tests can now be run on the simulator from Xcode, what would the advantage be, apart from possibly a small saving in execution time, of still separating your tests into logic and application tests?
由于应用程序测试现在可以从 Xcode 在模拟器上运行,除了可能会节省一点执行时间之外,仍然将您的测试分为逻辑测试和应用程序测试还有什么好处?
The differentiation as per the Apple docs:
根据Apple 文档的区别:
Logic tests. These tests check the correct functionality of your code in a clean-room environment; that is, your code is not run inside an application. Logic tests let you put together very specific test cases to exercise your code at a very granular level (a single method in class) or as part of a workflow (several methods in one or more classes). You can use logic tests to perform stress-testing of your code to ensure that it behaves correctly in extreme situations that are unlikely in a running application. These tests help you produce robust code that works correctly when used in ways that you did not anticipate. Logic tests are iOS Simulator SDK–based; however, the application is not run in iOS Simulator: The code being tested is run during the corresponding target's build phase.
Application tests. These tests check the functionality of your code in a running application. You can use application tests to ensure that the connections of your user-interface controls (outlets and actions) remain in place, and that your controls and controller objects work correctly with your object model as you work on your application. Because application tests run only on a device, you can also use these tests to perform hardware testing, such as getting the location of the device.
逻辑测试。这些测试在洁净室环境中检查代码的正确功能;也就是说,您的代码不在应用程序内运行。逻辑测试让您可以将非常具体的测试用例放在一起,以便在非常细粒度的级别(类中的单个方法)或作为工作流的一部分(一个或多个类中的多个方法)来练习您的代码。您可以使用逻辑测试对您的代码执行压力测试,以确保它在运行的应用程序中不太可能出现的极端情况下正确运行。这些测试可帮助您生成健壮的代码,当以您未曾预料到的方式使用时,这些代码可以正常工作。逻辑测试基于 iOS Simulator SDK;但是,该应用程序并未在 iOS 模拟器中运行:正在测试的代码在相应目标的构建阶段运行。
应用测试。这些测试检查正在运行的应用程序中代码的功能。您可以使用应用程序测试来确保您的用户界面控件(出口和操作)的连接保持原位,并在您处理应用程序时确保您的控件和控制器对象与您的对象模型正常工作。由于应用程序测试仅在设备上运行,您还可以使用这些测试来执行硬件测试,例如获取设备的位置。
回答by David R?nnqvist
Application tests compared to logic tests are really used for two different things:
与逻辑测试相比,应用程序测试实际上用于两种不同的事情:
Logic tests/unit tests are used to test very small behavior for one or a few methods, e.g. "Given that I create my object like this, is the value of a certain property what I expect it to be?"
逻辑测试/单元测试用于测试一种或几种方法的非常小的行为,例如“鉴于我像这样创建了我的对象,某个属性的值是否符合我的预期?”
Application testshowever are used to test the big picture, e.g. "Do I get the right data in my detail view when I tap on a certain table view cell?"
然而,应用程序测试用于测试大图,例如“当我点击某个表格视图单元格时,我是否在我的详细信息视图中获得了正确的数据?”