xctest

In XCTest UI Testing, how to check the background color of button, label , views?

走远了吗. 提交于 2019-12-04 05:14:14
I am trying to validate if the background color can be obtained in XCTest UI Testing, I am looking to compare the background color with the set value, so that i don't have to rely on image comparison XCTest is for functional testing, rather than asserting visual requirements. To test requirements such as background color, use a unit test to initialize the view controller in question and check the view's background color there. You don't need to rely on image comparison, and unit tests are a lot faster. 来源: https://stackoverflow.com/questions/38667435/in-xctest-ui-testing-how-to-check-the

Xcode 10 test failure when running on older iOS simulators - “Failed to load test bundle… no suitable image found”

旧城冷巷雨未停 提交于 2019-12-04 03:29:38
I've installed Xcode 10 and upgraded my iOS application to Swift 4.2. When I run my tests (both UI and Unit) via Xcode, on an iPhone simulator running iOS 12, the tests successfully start. When I attempt to run the tests on a simulator running a prior iOS version (e.g. iOS 10.3.1), I get a "failure to load the test bundle". These tests were running successfully on Xcode 9.4. I can run my app on this older simulator without an issue. The Xcode output is as follows ("Reading List" is the application name): 2018-09-16 15:11:36.667 ReadingList[11401:11478426] Failed to load test bundle from file:/

How can one use XCTAssertNil with optional structs?

我的梦境 提交于 2019-12-04 02:42:13
Update 3/23/2016 I just tested my original sample code below and it all compiles fine in XCode 7.3. Looks like XCTAssertNil was updated along the way to take an expression of type () throws -> Any? Therefore this question and answer may be no longer needed (except for a while with older versions of the compiler.) I'm writing my first unit tests in XCode with XCTest. I'm unsure how one can take advantage of XCTAssertNil as it seems to only compile when using certain types. It appears it will work with optionals made from classes and built-in primitives, but not structs. How would one go about

Scheme language setting ignored in iOS unit and ui tests

橙三吉。 提交于 2019-12-04 00:59:55
My final goal is to issue xcodebuild test from command line picking different schemes for different languages. Currently I have two schemes, the only difference between them is the application language. In one scheme it is English, in the other is Spanish. If I use xCode to run the application it works nice, it is launched with the language specified in the scheme I have picked, both EN or ES are okay. If I run the tests from xCode, language setting is ignored. Whichever scheme I pick, it doesn't matter, it is always displayed as the device language. The same on simulator. The same when

XCTest and CoreData

喜欢而已 提交于 2019-12-03 23:28:50
I am trying to Unit test my model in Xcode 5 by using the XCTest classes and methods. Because my model classes inherit of managedObject , I can't just instantiate (alloc/init) them and call the getters and setters or the methods I need to test. I need to create them by using the NSEntityDescription and use a managedObjectContext . That is with this point that I get troubles. I don't know where and how to create the managedObjectContext for unit tests purpose. If anyone has some advice or code examples, it will be very helpful. Thanks. Abizern I use an in memory store to for my unit tests and

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

ぃ、小莉子 提交于 2019-12-03 22:16:50
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 = [self expectationWithDescription:@"My Expectation"]; [MyClass loginOnServerWithEmail:@"example@email

How to run a fresh install of the application every time unit tests are run?

人走茶凉 提交于 2019-12-03 16:06:32
问题 I've setup some XCTest unit tests for my application and would like every time I run tests for it to run in a brand new install of the application. Currently when I run subsequent tests it runs the tests in the same application that was run before which has a lot of state information already changed by the previous tests. Is there a way to indicate that when you run unit tests that it should run the tests on a fresh version of your application? 回答1: Maybe this works, but only for Simulator.

How to write UI tests covering login with Facebook in Xcode?

谁都会走 提交于 2019-12-03 14:52:37
问题 I would like to write a UI test in Xcode covering a login with FBDSKLoginKit. However, Facebook iOS SDK uses SFSafariViewController presented to the user in order to authenticate her and unfortunately, there's no way how to interact with SFSafariViewController in UI tests in Xcode 7. Any ideas how to test the facebook login without interacting with SFSafariViewController ? 回答1: Swift 3 Xcode 8 solution func testFacebookLogin() { let app = XCUIApplication() // set up an expectation predicate

Use of Unit Test in Xcode 5

左心房为你撑大大i 提交于 2019-12-03 11:53:05
问题 I am writing my first bigger iOS project and I want to use as much of Xcode 5 as possible. Now I want to use testing but I have never done it before. My project uses come Views and dynamic `TableViews. How could I implement the test in the code, so that it makes sense? 回答1: Please start by watching WWDC '13 session 409 - Testing in Xcode 5. It's a very good starting point. Next, if you're not feeling confident of your approach to unit testing, I'd recommend reading "Test-Driven iOS

failing a XCTestCase with assert without the test continuing to run but without stopping other tests

ぃ、小莉子 提交于 2019-12-03 08:43:01
问题 I'm trying to test my application using the XCTest framework. I want my single test case to fail if some logical condition holds (using an assertion). I don't want the rest of the code in the test case to run, because this might lead to problems (access to null pointers, for example) I also want the rest of the test case to run normally, and just the failed test to be marked as failed. I've noticed XCTestCase has a property called continueAfterFailure. However, setting it to YES caused the