将单元测试添加到现有项目

将单元测试添加到现有项目

本文介绍了将单元测试添加到现有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您创建 XCode 4 项目时,它会询问您是否要包括单元测试.但是如何将它添加到没有它们创建的项目中呢?

When you create an XCode 4 project, it asks you if you want to include unit testing. But how do you add it to a project that's been created without them?

我用单元测试开始了一个项目,试图弄清楚它与我现有项目之间的唯一区别是新项目中的 Test.h 和 Test.m 文件.

I started a project with Unit Tests to try to figure it out, and it looks like the only difference between it and my existing project are the Test.h and Test.m files in the new project.

但是当我将它们移动到我的旧项目并尝试构建时,它说没有这样的文件或目录:SenTestingKit/SenTestingKit.h.对我来说,这看起来像是一个框架,但是如果我去构建阶段并尝试添加该框架,则没有可用的名为 SenTestingKit 的框架 :( 而新项目仅链接通常的嫌疑人:UIKit、CoreGraphics 和 Foundation,但是没有 SenTestingKit.

But when I move them into my old project and try to build, it says no such file or directory: SenTestingKit/SenTestingKit.h. That looks like a framework to me, but if I go to build phases and try to add the framework, there isn't one available called SenTestingKit :( And the new project only links the usual suspects: UIKit, CoreGraphics, and Foundation, but no SenTestingKit.

推荐答案

很高兴您提出这个问题 - 向项目添加测试永远不会太晚!

Glad you asked this question — it's never too late to add tests to a project!

  1. 在导航器中选择您的项目,打开您的目标面板
  2. 点击目标列表底部的 + 按钮
  3. 在iOS"选项卡的测试"部分下选择 iOS 单元测试包
  4. 提供所需信息,然后点击完成.

就是这么简单.Xcode 将为您生成一个目标、一些样板文件(例如 Info.plist)和一个初始测试用例文件.测试愉快!

It's that simple. Xcode will generate a target, some boilerplate files such as Info.plist and an initial test case file for you. Happy testing!

这篇关于将单元测试添加到现有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:17