xctest

How to test if a UIControlEvents has been fired

不问归期 提交于 2019-12-02 03:47:31
问题 I have a library implementing a custom UIControl with a method which would fire a .valueChanged event when called. I would like to test the method for that behavior. My custom control: class MyControl: UIControl { func fire() { sendActions(for: .valueChanged) } } And the test: import XCTest class ControlEventObserver: NSObject { var expectation: XCTestExpectation! init(expectation anExpectation: XCTestExpectation) { expectation = anExpectation } func observe() { expectation.fulfill() } }

How to call XCTest test case functions by order in Xcode 8?

孤人 提交于 2019-12-02 02:10:58
XCTest test functions was called in alphabetical order (before Xcode 8). With Xcode 8, I can not assume in which order the test cases are called by the system. Can someone throw light on it? Tests within a class are run in a random order in Xcode 8. This encourages tests to be independent and repeatable . I'm assuming that you want to run your tests in a specific order because they "chain" off of each other. For example, test_A logs a fake user in and test_B adds an item to the shopping cart. These type of tests should be avoided because they depend too much on each other. What if you want to

XCTest-iOS单元测试框架

自作多情 提交于 2019-12-01 20:24:41
Xctest 是iOS的单元测试框架,有objective-c和swift两种语言可以选择 Xcuitest 是iOS的UI测试框架 XCTest 官方文档地址: https://developer.apple.com/documentation/xctest XCTest 框架类似于python中的unit test框架,声明一个测试case继承XCTestCase和测试方法,测试方法以test开头,然后执行。 相关类介绍: Class XCTest XCTest类提供XCTestCase和XCTestSuite用于创建、管理和执行测试的共享功能。在大多数情况下,在项目中定义测试时,应该直接子类化XCTestCase。 包含了以下属性: name: test 的 name testCaseCount: case个数 testRun: XCTestRun对象来执行test testRunClass: 运行测试时实例化的XCTestRun子类,以保存测试结果。 包含了以下方法: perform( XCTestRun ): 执行一个特定的测试 run():创建testRunClass指定的类的实例,并将其作为参数传递给执行perform(_:)方法。 还包含了一系列的断言方法 Class XCTestCase 具体的属性和方法看文档,主要包含代码块性能检测,异步测试(例如打开文档

Adding test target to an existing project is not working

寵の児 提交于 2019-12-01 16:32:55
I need to add test cases to an existing project, so I tried adding a new test target via File -> New -> Target -> Cocoa Touch Testing Bundle From the test navigator filter bar. Even after adding, the target is not getting listed in the test filter bar. May be because of this issue, Product -> Test option is diabled in my project. Also I could see some differnce between the build setting in my project and another sample project I started in Xcode 6.1 in which Product -> Test option is enabled and everything working fine for Test cases. Please find the build settings screen shots. Any help is

Unable To Run Unit Tests in Xcode 11: The run destination * is not valid for tests you have chosen to perform

主宰稳场 提交于 2019-12-01 15:06:15
问题 Pretty sure my tests were running fine before I updated from Xcode 10.3 to Xcode 11. Now when I try to run a test I get the following error. The run destination iPhone 5s is not valid for tests you have chosen to perform. Please select a run destination which supports the tests that you wish to perform. As an experiment, I tried creating a brand new test target and running the example tests that it gives you and the error is the same. I've also tried with different simulators. 回答1: Check your

multiple testPerformance with XCTestCase objective-C

这一生的挚爱 提交于 2019-12-01 08:33:30
I have 2 performance test methods in test class. If i run them separately they pass. If i run hole class methods they fail with message: **** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'API violation - multiple calls made to -[XCTestExpectation fulfill].'* Is there any way to include couple performance tests in 1 class? here is sample code: - (void)testPerformanceAuthenticateWithLogin { XCTestExpectation *authenticateExpectation = [self expectationWithDescription:@"Authenticate With Login"]; __block int userID = 0; [self measureBlock:^{

XCTest fails when calling [NSBundle mainBundle]

佐手、 提交于 2019-12-01 06:43:29
问题 I have some code that calls [NSBundle mainBundle] at some point, mainly to read/set preferences. When I unit test the method, the test fails because the test's mainBundle does not contain the file. This is a known issue, that Apple won't fix as they consider it is not a bug: the gist of their reply is that XCTest is working correctly by returning it’s own main bundle instead of the bundle of the test target. Previously our codebase was using a category override on NSBundle 's +mainBundle

Why should I use a separate test host for running XCTests and how should I do that?

允我心安 提交于 2019-12-01 06:11:07
I once asked a question related to XCTests . And in one of the answers I was told that it is a common practice to use a separate test host (other than the main app) when running unit tests (at least, in iOS development). I tried to find some sources about it, but I couldn't I understand, that it is probably a best practice, so I would really like to understand it. Could someone explain to me why is it important, what benefits do I get from it and how should I go about doing it? Links to some articles explaining the issue will be much appreciated. P.S. I understand that I need special

Is it possible to test IBAction?

我的未来我决定 提交于 2019-12-01 05:43:46
It is kinda easy to unit test IBOutlets, but how about IBActions? I was trying to find a way how to do it, but without any luck. Is there any way to unit test connection between IBAction in a View Controller and a button in the nib file? For full unit testing, each outlet/action needs three tests: Is the outlet hooked up to a view? Is the outlet connected to the action we want? Invoke the action directly, as if it had been triggered by the outlet. I do this all the time to TDD my view controllers. You can see an example in this screencast . It sounds like you're asking specifically about the

Why should I use a separate test host for running XCTests and how should I do that?

徘徊边缘 提交于 2019-12-01 05:02:59
问题 I once asked a question related to XCTests. And in one of the answers I was told that it is a common practice to use a separate test host (other than the main app) when running unit tests (at least, in iOS development). I tried to find some sources about it, but I couldn't I understand, that it is probably a best practice, so I would really like to understand it. Could someone explain to me why is it important, what benefits do I get from it and how should I go about doing it? Links to some