xctest

How can I test Swift files in Xcode using XCTest without having to build the entire app?

只谈情不闲聊 提交于 2019-12-12 20:15:29
问题 What I'm trying to do is test a Swift file frequently after making tiny changes to the file. The file may contain one or more structs and classes. I don't care about a concept of an "app" because this is purely an academic exercise to practice some new concepts I've learned. I just want to test the file and don't care about the app and anything related to the app. You may be asking why? Speed. I want it to be really fast to test, right now it takes a few seconds for the most trivial example.

iOS: how to run XCTest on device?

﹥>﹥吖頭↗ 提交于 2019-12-12 16:09:17
问题 I currently learning XCTest for the purpose of unit testing. I was able to run the default template XCtest on the simulator without any problem. I could all the green ticks in the test navigation view. However, when I ran them on the device with my app as host application, nothing happens. My app was launched on the device and the XCTest did not seem to run. I even put a break point in the test and it did not break. Also, in the simulator, the app automatically stops when tests finish,

UIWindow.makeKeyAndVisible() throws “props must have a valid clientID” error in XCTest

强颜欢笑 提交于 2019-12-12 14:28:49
问题 I am testing a UIViewController in Xcode with an XCTest. In order to test some navigation and alert functionality I need to put my view controller in a UIWindow. I do so with the following code: let myViewController = UIViewController() let window = UIWindow(frame: UIScreen.main.bounds) window.rootViewController = myViewController window.makeKeyAndVisible() However when makeKeyAndVisible() is called my test fails with the following error: 2018-01-04 10:56:31.068462-0500 xctest[7858:315680] **

Why does the first run of “XCTestCase -measureBlock:” takes so much time?

南笙酒味 提交于 2019-12-12 11:28:26
问题 I'm using Xcode 7. iPhone 5s simulator (iOS 9.0). I'm trying to use XCTestCase -measureBlock: to measure time spent on some of my functions. This runs the code inside the block 10 times and report the results how long each run takes, the average, STDEV, etc. It turns out that the time of first run is always very high, like 400-500% higher. Same happens for a very simple method, or even nothing in the measure block. I don't have anything in my - (void)setUp or - (void)tearDown . Result of

Error with XCTestExpectation: API violation - multiple calls made to -[XCTestExpectation fulfill]

旧城冷巷雨未停 提交于 2019-12-12 08:17:53
问题 I'm using XCTestExpectations in Xcode 6 (Beta 5) for asynchronous testing. All my asynchronous tests pass individually every time I run them. However, when I try to run my entire suite, some tests do not pass, and the app crashes. The error I get is says API violation - multiple calls made to -[XCTestExpectation fulfill] . Indeed, this is not true within a single method; my general format for my tests is shown below: - (void) someTest { /* Declare Expectation */ XCTestExpectation *expectation

Nested function selector in swift for testing

左心房为你撑大大i 提交于 2019-12-12 06:19:33
问题 Here is my situation and perhaps there is an easier way to do this: I'm testing some stuff that uses notifications and I didn't want to have to define my expectations as class level optional variables so I was wondering if I can make them local variables to a function in such a way that my notification handler can access them. My attempt was to make notification handler functions as nested functions inside my top level test function - but i've run into selector naming issues as I'm not sure

Prevent XCUIElementQuery from being reevaluated

不想你离开。 提交于 2019-12-12 06:09:17
问题 In the WWDC Session about UI Testing in Xcode you can learn that queries are evaluated when you actually synthesise properties or read values. So when are queries evaluated? So they are not actually evaluated just when you create them. They are evaluated on-demand or as they are needed. This means that with an element, the query will be evaluated when you synthesize events or read property values. You can create the element but until you use it, the query won't be evaluated. Similarly if you

Xcode5: creating new testing target

这一生的挚爱 提交于 2019-12-12 05:00:02
问题 I'm trying to create my first XCTestCase within my existing iOS+Mac project. I created a new test class, and I see that it created a new test target for me in my project, but the new scheme has none of the linked libraries and source code files from my existing target. It just shared the scheme from the existing target, but none of the project details. I don't want to go add each and every source file and framework library into the new test target. Is there a way to simply create a new test

Unit testing of Object

旧巷老猫 提交于 2019-12-12 04:56:02
问题 I am a learner of objective c and struck up doing unit testing, i want to unit test below object @interface Media : NSObject{ } @property (nonatomic, readonly) NSString *name; @property (nonatomic, readonly) NSString *sex; @property (nonatomic, readonly) NSString *Description; - (instancetype)initWithDictionary:(NSDictionary *)mediaData; @end #import "Media.h" @interface Media() @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *sex; @property (nonatomic,

XCTest UI Record and Play - Simulator not updating UI

。_饼干妹妹 提交于 2019-12-12 04:24:20
问题 Apple released a new UI Testing framework 2 days ago during WWDC2015. I'm trying to write a test case and when I try to record the UI testing, to generate the scaffolding code, it looks the code is being generated, however the UI on the simulator is not actually updating. i.e When I tap on a button, the code is generated to actually find the button and tap, but the button is not actually tapped simultaneously on the simulator. So basically I'm not able to go to the next screen on the