如何在不点击“运行”按钮的情况下启动 GHUnit 测试?
我使用 GHUnit 框架来测试静态库。此时我需要点击“运行”按钮来开始我的测试。但我想在应用程序启动时开始测试,因为我需要 teamcity 启动我的 testApp。那么如何修改标准 UI 并自动启动测试呢?
I use GHUnit framework for testing static library. At this moment I need tap the button Run to start my tests. But I would like to start tests when application launched because I need teamcity launch my testApp. So how can I modified standart UI and start tests automatic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
做产品->编辑方案...->参数 ->环境变量,然后将
GHUNIT_AUTORUN
设置为YES
。Do Product -> Edit Scheme… -> Arguments -> Environment Variables, then set
GHUNIT_AUTORUN
toYES
.使您的单元测试目标依赖于您的应用程序,以便您始终在单元测试之前构建应用程序。
然后,只需添加一个“setUp()”方法来启动您的应用程序(并等待它启动),然后再继续。
检查您的应用程序是否已在运行:
NSArray* apps = [[NSWorkspace sharedWorkspace] valueForKeyPath:@"launchedApplications.NSApplicationBundleIdentifier"];
BOOL myAppIsRunning = [apps containsObject: com.mycompany.myapp];
启动您的应用程序(在 setUP() 中)并等待:
[[NSWorkspace共享工作空间]launchAppWithBundleIdentifier:com.mycompany.myapp选项:NSWorkspaceLaunchWithoutActivationadditionalEventParamDescriptor:NULL launchIdentifier:nil];
while (![self isRunning]) // 见上文
{
睡眠(1);
[
Make your unit test target dependent on your application, so that you always built the application before the unit tests.
Then, simply add a "setUp()" method to launch your app (and wait for it to be launched) before continuing.
Check that your application is already running:
NSArray* apps = [[NSWorkspace sharedWorkspace] valueForKeyPath:@"launchedApplications.NSApplicationBundleIdentifier"];
BOOL myAppIsRunning = [apps containsObject: com.mycompany.myapp];
Launch your application (in setUP()) and wait:
[[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier: com.mycompany.myapp options: NSWorkspaceLaunchWithoutActivation additionalEventParamDescriptor: NULL launchIdentifier: nil];
while (![self isRunning]) // see above
{
sleep(1);
}