Skip to content

Instantly share code, notes, and snippets.

View ccabanero's full-sized avatar

Clint Cabanero ccabanero

View GitHub Profile
@ccabanero
ccabanero / Sample iOS Unit Tests: Working with a ViewController composed of MKMapView
Last active February 8, 2021 08:46
Sample iOS Unit Tests: Working with a ViewController composed of MKMapView
import UIKit
import XCTest
import MapKit
class ExampleTests: XCTestCase {
//declaring the ViewController under test as an implicitly unwrapped optional
var viewControllerUnderTest : ViewController!
override func setUp() {
@ccabanero
ccabanero / Sample iOS Unit Tests: Working with a ViewController composed of a UIButton
Last active May 12, 2016 18:55
Sample iOS Unit Tests: Working with a ViewController composed of a UIButton
import XCTest
@testable import projectname
class ExampleTests: XCTestCase {
var viewControllerUnderTest: MyViewController!
override func setUp() {
super.setUp()
@ccabanero
ccabanero / Sample iOS Unit Tests: Working with a ViewController composed of a UILabel
Last active March 9, 2021 15:08
Sample iOS Unit Tests: Working with a ViewController composed of a UILabel
import XCTest
@testable import UnitTests
class ExampleTests: XCTestCase {
var viewControllerUnderTest: ViewController!
override func setUp() {
super.setUp()
@ccabanero
ccabanero / Sample iOS Unit Tests: Model class that adopts the MKAnnotation protocol.
Last active May 12, 2016 18:59
Sample iOS Unit Tests: Model class that adopts the MKAnnotation protocol.
#import <XCTest/XCTest.h>
#import "FerryTerminalAnno.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface FerryTerminalAnnoTest : XCTestCase
@property (nonatomic, strong) FerryTerminalAnno *annoUnderTest;
@end
@ccabanero
ccabanero / Sample iOS Unit Tests: Model can Process the Response From Async Network Request
Last active May 12, 2016 18:59
Sample iOS Unit Tests: Model can Process the Response From Async Network Request
- (void)testFetchingFoursquareVenues {
//create a semaphore with initial value
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
NSURL *url = [NSURL URLWithString:@"https://api.yourawesome.com"];
NSURLSessionDataTask *task = [self.session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
XCTAssertNil(error, @"NSURLSessionDataTask returned completed with Error: %@", error);
@ccabanero
ccabanero / Sample iOS Unit Tests: Confirming Model object instantation of a NSManagedObject subclass
Last active May 12, 2016 19:00
Sample iOS Unit Tests: Confirming Model object instantation of a NSManagedObject subclass
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "SightingReport.h"
#import "SightingReport+CoreData.h"
#import "AppDelegate.h"
@interface SightingReportTest : XCTestCase
//for accessing CoreData NSManagedObjectContext in assertions
@property (nonatomic, strong) AppDelegate *appDelegate;
@ccabanero
ccabanero / Sample iOS Unit Tests: Confirming that a NSManagedObject subclass Category properly seeds CoreData
Last active May 12, 2016 19:00
Sample iOS Unit Tests: Confirming that a NSManagedObject subclass Category properly seeds CoreData
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "AppDelegate.h"
#import "Item.h"
#import "Item+CoreData.h" //note: Item+CoreData is a category for the Item entity (i.e. NSManagedObject subclass)
@interface Item_CoreDataTest : XCTestCase
//for accessing CoreData NSManagedObjectContext in assertions
@property (nonatomic, strong) AppDelegate *appDelegate;
@ccabanero
ccabanero / ios-healthkit-healthstore-objc
Last active August 29, 2015 14:07
Setting up a Health Store with Authorization from User
#import "ViewController.h"
#import <HealthKit/HealthKit.h>
@interface ViewController ()
@property (nonatomic, strong) HKHealthStore *healthStore;
@end
@ccabanero
ccabanero / remove uitableviewcell indentation
Created October 16, 2015 10:36
remove uitableviewcell indentation
// For removing the separator line indentation from a UITableViewCell
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if(tableView.respondsToSelector("setSeparatorInset:")) {
tableView.separatorInset = UIEdgeInsetsZero
}
if(tableView.respondsToSelector("setLayoutMargins:")) {
tableView.layoutMargins = UIEdgeInsetsZero
}
@ccabanero
ccabanero / Sample iOS Integration Test: Test When Model performs work over the Network
Last active June 10, 2019 22:06
Sample iOS Integration Test: Test When Model performs work over the Network
// Example of an asynchronous unit test
func testUserLogin() {
let readyExpectation = expectationWithDescription("ready")
User.loginWithUsername("kris@bla.org", password: "blah") { (isSuccess) -> Void in
let expectedLoginSuccessStatus = true