xctest

How do I use XCTest to test if a navigationBar is not set to a specific colour in objective-C?

大憨熊 提交于 2019-12-11 14:57:07
问题 Trying to test for navigationBar colour of a table view controller. I've set the barTintColor of the navigationController in the table view controller. I have written the following test: - (void)testNavBarColourOfMasterViewController { VAGMasterViewController *mvc = [[VAGMasterViewController alloc] init]; [mvc view]; XCTAssertEqualObjects([[[mvc navigationController] navigationBar] barTintColor], [UIColor whiteColor]); } Error: test failure: -[VAGMasterViewControllerTests

Cannot call value of non-function type 'URLSession' error with mockURLSession

蓝咒 提交于 2019-12-11 14:48:56
问题 I'm trying to unit test URLSession delegates with mockData. This is the delegate function that is being tested: urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) This is the unit test so far: func test_urlSession(){ let mockSession = MockURLSession(mockResponse: MockURLSession().successHttpURLResponse(request: self.urlRequest!) as! HTTPURLResponse) //error here sut?.urlSession(mockSession, task: MockURLSessionDataTask, didCompleteWithError: Error) }

accessing app delegate object in XCTestCase class causes misaligned_stack_error_ swift

空扰寡人 提交于 2019-12-11 07:57:48
问题 I am trying to perform unit testing in swift. I defined my test case class like this: import XCTest import CoreData import UIKit class LazyLoadingCheckTests: XCTestCase { var appDelegate : AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate override func setUp() { super.setUp() // Put setup code here. This method is called before the invocation of each test method in the class. } override func tearDown() { // Put teardown code here. This method is called after the

“No such module” when using @testable in Xcode Unit tests

若如初见. 提交于 2019-12-11 07:34:01
问题 I recently updated to Xcode 7 beta 5. I tried adding a unit test to an earlier project, but I am getting the error message "No such module [myModuleName]" on the @testable import myModuleName line. I tried cleaning the project with Option Clean Build Folder checking that "Enable Testability" (debug) was set to Yes in the Build Options deleting the tests target and then re-adding the iOS Unit testing bundle None of this worked for this project (but I have gotten testing to work in another

Read local JSON file in XCUITest

橙三吉。 提交于 2019-12-11 07:29:28
问题 I am writing UI tests for iOS application. I want to read data from a local json file. I am using the following code to get the path for my json file: func testExample() { readJSON() } func readJSON(){ let bundle = Bundle(for:myTestClass.self) if let path = bundle.url(forResource: "myurl", withExtension: "json"){ print("Got the path") print(path) } else{ print("Invalid filename/path") } I have tried using the solution for the following stackoverflow question : Reading in a JSON File Using

Cannot convert value of type 'Foo!' to expected argument type 'Foo!'

谁都会走 提交于 2019-12-11 05:09:39
问题 I'm baffled by something I've run into a couple of times. I sometimes get errors similar to the following Cannot convert value of type 'Foo!' to expected argument type 'Foo! ' I've searched SO, but haven't really found anything that explains why Foo! isn't the same as Foo!. Here's an example: // FooViewModel.swift class FooViewModel: BaseViewModel { fileprivate var foo: Foo! fileprivate var bar: Bar = Bar() init!(model: Foo!) { super.init() foo = model } override init() { super.init() } func

Launching Unit Tests from ios-sim doesn't execute all tests

霸气de小男生 提交于 2019-12-11 03:13:49
问题 I'm trying to launch tests from my CI using ios-sim using approach described here: https://confluence.atlassian.com/display/BAMBOO/Xcode , but instead of SenTest I'm using XCTest in my application, so last parameter should be not --args -SenTest All but something like -args -XCTest All and if I use such parameter, not all tests are executed. How can I specify executing all tests using XCtest? If I use --args -XCTest -test All none of tests are executed. The full launch command: ios-sim launch

Always the default implementation of protocol gets called even after implementing the method in class extension in an XCTest file

十年热恋 提交于 2019-12-11 03:05:58
问题 I have a protocol protocol SomeProtocol { func method() } and its implementation extension SomeProtocol {func method(){--implementation--}} In build target i have a class confirming to this protocol class SomeClass: SomeProtocol { func doSomething() { method() } } What i want is i want to have a different implementation of the protocol method in my test target, in my XCTest file. For that what i did was i extended the SomeClass and wrote my implementation there. extension SomeClass {func

Is it possible to unit test a WindowController thats initialised with a nib?

梦想的初衷 提交于 2019-12-11 02:27:18
问题 I have a simple Mac OS application that comes with the default MainMenu.xib . In there I have a second window for preferences and a PreferencesWindowController . I'd like to get the following test working: @implementation TestPreferencesWindow - (void)testProtectsUserPasswordByUsingAPasswordField { PreferencesWindowController *controller = [[PreferencesWindowController alloc] initWithWindowNibName:@"MainMenu"]; XCTAssertInstanceOf([[controller passwordField] class], NSSecureTextField); } @end

OK to call test cases from within other test cases in XCTest

為{幸葍}努か 提交于 2019-12-11 01:59:18
问题 I'm build a set of XCTestCase methods to exercise the code around my core data model. I am planning on calling some of the test methods from other test methods so I can see different combinations of data while keeping the code to a minimum. I can't imagine why this would not work, but I'm wondering what the world thinks and whether this is considered to be good practice. Here's what it would look like: @interface sessionTests : XCTestCase @property (strong) Model *model; @end - (void)setUp {