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

编程入门 行业动态 更新时间:2024-10-26 08:34:37
本文介绍了将单元测试添加到现有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当您创建 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.

推荐答案

针对 Xcode 10.2 更新了答案.

Answer updated for Xcode 10.2.

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

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

  • 在导航器中选择您的项目,打开您的目标面板,
  • 点击目标列表底部的 + 按钮,
  • 在iOS"选项卡的测试"部分下选择 iOS 单元测试包,
  • 提供所需信息,然后点击完成.
  • 就是这么简单.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!

    更多推荐

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

    本文发布于:2023-11-14 11:28:17,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1587090.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:单元测试   项目

    发布评论

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

    >www.elefans.com

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