简体   繁体   English

OCUnit-iOS 5-如何在我的应用程序中测试文件?

[英]OCUnit - iOS 5 - How do I test files in my app?

I am trying to build simple tests to see if files I need (images, videos, audio files) are in my app. 我正在尝试建立简单的测试,以查看我需要的文件(图像,视频,音频文件)是否在我的应用程序中。 Whenever I try to do something such as: 每当我尝试执行以下操作时:

if (![[NSFileManager defaultManager] fileExistsAtPath:@"Menu Loop.mp3"])
{ 
    STFail(@"File does not exist");
}
else
{
    NSLog(@"Passed");
}

It says the file does not exist. 它说该文件不存在。 I can see the file is there, and I know it is failing because the file in the app folder and not in the test folder. 我可以看到文件在那里,而且我知道它失败了,因为该文件位于app文件夹而不是test文件夹中。 Is there a way of getting out of the test folder to test if the files exists without adding all of the files to the test folder? 有没有一种方法可以在不将所有文件都添加到测试文件夹的情况下退出测试文件夹以测试文件是否存在? I have tried doing something such as fileExistsAtPath:@"../appfolder/Menu Loop.mp3" to try to navigate out of the test folder, but it unfortunately does not work that way either. 我曾尝试执行诸如fileExistsAtPath:@“ ../ appfolder / Menu Loop.mp3”之类的内容来尝试导航到测试文件夹之外,但不幸的是,该方法也不起作用。

Thanks in advance! 提前致谢!

You cannot directly access folders like that through the iOS SDK. 您无法通过iOS SDK直接访问类似的文件夹。 You must save and read files using the system functions that return the proper path: 您必须使用返回正确路径的系统功能来保存和读取文件:

NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
NSString *pathToMenuLoopFile = [rootPath stringByAppendingPathComponent:@"Menu Loop.mp3"];

If you are looking to load files that you include in your Xcode project, please take a look at this post: Loading data files in iPhone project 如果您要加载Xcode项目中包含的文件,请看一下这篇文章: 在iPhone项目中加载数据文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM