运行XCTests时访问主应用程序包 [英] Accessing Bundle of main application while running XCTests

查看:63
本文介绍了运行XCTests时访问主应用程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试中 target->一般->测试:将主机应用程序"设置为无" ,这样就不会启动任何应用程序.

In tests target -> General -> Testing: set Host Application to None, so that no app gets launched.

但是在那种情况下,我不能使用 Bundle.main.resourcePath 并访问我的主应用程序的资源(其中一些命令文件作为资源包含在内,我需要使用 Process来运行它们()).

But in that case I cannot use Bundle.main.resourcePath and access resources of my main application (in which some command files are included as resources and I need to run them using Process()).

有人可以提出解决方案吗?

Could anyone suggest a solution?

推荐答案

还将文件添加到测试目标的"复制捆绑包资源"中,然后使用以下代码获取资源的路径,而不是"\(Bundle.main.resourcePath!)/test.command"

Added file to 'Copy Bundle Resources' of Test target also, then used following code to get path for resource , instead of "\(Bundle.main.resourcePath!)/test.command"

让testBundle = Bundle(for:type(of:self))let path ="\(testBundle.resourcePath!)/test.command""

这篇关于运行XCTests时访问主应用程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆