xctest

Testing that a particular image was copied to pasteboard

╄→尐↘猪︶ㄣ 提交于 2019-12-24 17:57:16
问题 I'm writing a test to verify a feature which copies an image to the pasteboard. Here's the test, as I would prefer to write it: // reset the paste board UIPasteboard.generalPasteboard.image = nil; //<-- this explodes XCTAssertNil(UIPasteboard.generalPasteboard.image); // Grab some random existing image UIImage *image = [UIImage imageNamed:@"some-image"]; MJKMyClass *myInstance = [[myInstance alloc] initWithImage:image]; [myInstance doSomethingThatCopiesImageToPasteboard] XCTAssertNotNil

Testing that a particular image was copied to pasteboard

半腔热情 提交于 2019-12-24 17:57:06
问题 I'm writing a test to verify a feature which copies an image to the pasteboard. Here's the test, as I would prefer to write it: // reset the paste board UIPasteboard.generalPasteboard.image = nil; //<-- this explodes XCTAssertNil(UIPasteboard.generalPasteboard.image); // Grab some random existing image UIImage *image = [UIImage imageNamed:@"some-image"]; MJKMyClass *myInstance = [[myInstance alloc] initWithImage:image]; [myInstance doSomethingThatCopiesImageToPasteboard] XCTAssertNotNil

XCTest - Xcode crashing when trying to record elements inside WKWebView

谁说我不能喝 提交于 2019-12-24 09:58:36
问题 Create a new Swift Xcode Single view project with UI test target. In Main.storyboard select ViewController, then Editor/Embed in/Navigation Controller. Change ViewController.swift to the following code: import UIKit import WebKit class ViewController: UIViewController, WKNavigationDelegate { var _webView: WKWebView! override func loadView() { _webView = WKWebView() _webView.navigationDelegate = self view = _webView } override func viewDidLoad() { super.viewDidLoad() let url = URL(string:

How to reliably install and setup Quick test framework on Xcode 8?

牧云@^-^@ 提交于 2019-12-24 07:11:56
问题 Background : While working on this answer I noticed that it's not so trivial to properly set up Quick test framework on Xcode properly. In my case, it took 3-4 failed attempts to finally have a working version. And still, I'm not sure where my previous attempts were wrong. Or more importantly why the questioner in that thread could have duplicate run each time. Then it also took him several attempts to finally have a working one. Question : I am asking if any of you have a reliable way to set

Getting nil value for the variable in Unit Test using XCTest

冷暖自知 提交于 2019-12-24 06:44:45
问题 The appDelegate instance is showing nil value, test case "testAppDelegate" is getting failed. The same is working in the sample code provided by apple developer site but there SenTestCase is being used, please help me out, even the target is set as per the WWDC 2013 video "Testing in Xcode 5 session 409" @interface Tests : XCTestCase { AppDelegate *appDelegate; AppViewController *appVC; UIView *appView; } @end @implementation Tests - (void)setUp { [super setUp]; appDelegate = [[UIApplication

Unit testing in SwiftUI

妖精的绣舞 提交于 2019-12-24 00:59:29
问题 I am trying to write unit tests for SwiftUI views but finding zero resources on the web for how to go about that. I have a view like the following struct Page: View { @EnvironmentObject var service: Service var body: some View { NavigationView { ScrollView(.vertical) { VStack { Text("Some text")) .font(.body) .navigationBarTitle(Text("Title"))) Spacer(minLength: 100) } } } } } I started writing a test like this func testPage() { let page = Page().environmentObject(Service()) let body = page

Can't get GoogleMaps SDK to work on Xcode Test Target (works on App Target)

时光怂恿深爱的人放手 提交于 2019-12-23 17:33:29
问题 The Setup I have successfully integrated the GoogleMaps SDK into my Swift 2 project using CocoaPods. My setup is pretty much that suggested by the Ray Wenderlich tutorial on the subject. The only difference I can find is, I have to add this line to AppDelegate: import UIKit import GoogleMaps // <- THIS LINE @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { ... ...in order to use the framework's classes. The tutorial suggests importing: #import <GoogleMaps/GoogleMaps.h

How to include SwiftyUserDefaults.swift in the target for UI Test class in Xcode?

↘锁芯ラ 提交于 2019-12-23 12:47:44
问题 I have made a user interface testing class in Xcode swift application for iPhone, that acts on the screen and presses some buttons. However the build fails because some of the libraries (SwiftyUserDefaults.swift, and SwiftyJSON.swift) are not included in the target for Test class - I get the error: When I included the class SwiftyJSON.swift in the compile resources for the test class like this: I get another error, that essentially means that I included the same file twice: What should I do?

Table view's `cellForRow(at:)` is `nil` in Unit Test

微笑、不失礼 提交于 2019-12-23 10:15:45
问题 In Unit Test, I have a simple table view with a bunch of basic cells (cells with just a label). I would like to access the cell using cellForRow(at:) , so I can test thing like selecting and deselecting the row programmatically, but this cellForRow query always returns nil . There is some discussion online that I should be using the data source's tableView(_, cellForRowAt:) instead. This is not my intention. I only want to test the cell's visibility, test selecting and deselecting them. To

XCTest'ing a tuple

血红的双手。 提交于 2019-12-23 08:55:14
问题 I am trying to build a unit test like so: // region is a (Double, Double) tuple XCTAssertEqual(region, (0.0, 200.0)) But Xcode is giving me an error: Cannot invoke 'XCTAssertEqual' with an argument list of type ((Double, Double), (Double, Double)) Is there a different way to test tuples without extracting their members and testing individually? 回答1: XCTAssertEqual requires that the two parameters passed to it are Equatable , which you can see from the method signature. Note that expression1