在Xcode中多次自动运行测试用例 [英] Automatically Running a Test Case Many Times in Xcode

查看:134
本文介绍了在Xcode中多次自动运行测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode中,有没有办法让我自动运行一个测试用例n次?

In Xcode, is there a way for me run a single test case n times automatically?

这样做的原因是我的一些beta版测试人员遇到了随机问题在我的应用程序崩溃。我在TestFlight中看到崩溃日志以及堆栈跟踪,但我无法重现崩溃。

Reason for doing this is that some of my beta testers are encountering random crashes in my app. I see the crash logs in TestFlight, along with the stack trace, but I can't reproduce the crash.

崩溃很少发生,但是当它发生时,它总是在用户尝试创建数据库记录时发生,然后上传到服务器。崩溃日志的问题是我的代码没有在他们的堆栈跟踪中出现(所有UIKit和CoreFoundation的东西 - 每次都不同)。

The crash happens infrequently but when it does, it always happens when users are trying to create a DB record, which then gets uploaded to a server. The problem with the crash logs is that my code does not make an appearance in their stack traces (all UIKit & CoreFoundation stuff - and different each time).

我的解决方案是为应用程序的那部分运行测试100次,设置异常断点,试图在我的开发环境中触发错误。但是我不知道如何自动执行此操作。

My solution is to run the test for that part of the app 100s of times, with the exception breakpoint set, to try to trigger the bug in my dev environment. But I don't know how to do this automatically.

推荐答案

在Xcode中,没有。

In Xcode as such, no.

您可以创建一个 XCTestCase 类,它挂接到它继承的测试运行方法以返回多次运行,但这往往很烦人,大多数没有记录。

You can create an XCTestCase class that hooks into the test-running methods it inherits to return multiple runs, but that tends to be annoying and mostly undocumented.

反而有一个元测试反复调用你的其他测试方法可能更容易:

It's probably easier to instead have a "meta-test" that calls out to your other test method repeatedly:

func testOnce() {}

func testManyTimes() {
    for _ in 0..<1000 { testOnce() }
}

您可能需要调用一些每测试设置/拆卸方法。你也许可以通过改变循环体来解决这个问题:

You might need to call out to some per-test setup/teardown methods. You could perhaps work around that by instead making the loop body be something like:

let test = XCTestCase(selector: #selector(testOnce))
test.invokeTest()

这将依靠你的XCTest机器标准测试使用,但它可能会抱怨没有连接到 XCTestCaseRun (或没有)。

This would lean on the XCTest machinery that your standard tests use, but it might gripe about not being wired into an XCTestCaseRun (or not).

这篇关于在Xcode中多次自动运行测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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