GitXplorerGitXplorer
p

JPSimulatorHacks

public
105 stars
18 forks
4 issues

Commits

List of commits on branch master.
Unverified
f9621e30ac4d54deb1f5675e97ddb9bf881bd588

Bump version

pplu committed 7 years ago
Unverified
1eeb838b9fd33edb53ad93172890a916341416fe

Merge pull request #17 from pzearfoss-capone/master

pplu committed 7 years ago
Unverified
3edef1379a1253d5f2e4ff4e0bb7c942f5f15caa

updates readme

committed 7 years ago
Unverified
e6fa200e01212b98c59eb65b497ff542ccb90fe3

adds shared scheme

committed 7 years ago
Unverified
f6369fe0e844a31fb95b0972e8fbe3dbc92bfec9

Adds new project and target for dynamic framework

committed 7 years ago
Unverified
777abb93c5b66f7c2adb33d10294743351e3c32b

Merge pull request #15 from abdullahselek/master

pplu committed 7 years ago

README

The README file for this repository.

Build Status Carthage compatible

JPSimulatorHacks

Description

Hack the Simulator in your tests (grant access to photos, contacts, calendar ...).

Did you ever have the problem that your code was wrapping the AddressBook, the EventKit or the ALAssetsLibrary APIs? Running tests can be annoying then. There's this UIAlertView asking the user to grant access to the contacts and photos, which blocks and breaks your tests. Using JPSimulatorHacks you can easily grant this access before running your tests.

If you encounter any problems, please check out the caveats documented below.

Installation

Install JPSimulatorHacks with CocoaPods

pod 'JPSimulatorHacks'

Or, install via Carthage

github "plu/JPSimulatorHacks"

Usage

AddressBook

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToAddressBook];
}

@end

This will grant access to the addressbook for the current bundle identifier. There's also an API to specify the bundle identifier, if necessary:

+ (BOOL)grantAccessToAddressBookForBundleIdentifier:(NSString *)bundleIdentifier;

Calendar

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToCalendar];
}

@end

This will grant access to the calendar for the current bundle identifier. There's also an API to specify the bundle identifier, if necessary:

+ (BOOL)grantAccessToCalendarForBundleIdentifier:(NSString *)bundleIdentifier;

HomeKit

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToHomeKit];
}

@end

This will grant access to HomeKit for the current bundle identifier. There's also an API to specify the bundle identifier, if necessary:

+ (BOOL) grantAccessToHomeKitForBundleIdentifier:(NSString *)bundleIdentifier;

Photos

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToPhotos];
}

@end

This will grant access to the photos library for the current bundle identifier. There's also an API to specify the bundle identifier, if necessary:

+ (BOOL)grantAccessToPhotosForBundleIdentifier:(NSString *)bundleIdentifier;

You can also add some test images from a given URL. The method will block until the Asset has been stored. This is helpful so your tests will only start after the Asset is available.

[JPSimulatorHacks grantAccessToPhotos];
NSURL *assetURL = [NSURL URLWithString:@"https://raw.githubusercontent.com/plu/JPSimulatorHacks/master/Data/test.png"];
ALAsset *asset = [JPSimulatorHacks addAssetWithURL:assetURL];

Contacts (iOS 9)

This will grant permission for the new Contacts Framework which comes with iOS 9.

#import <JPSimulatorHacks/JPSimulatorHacks.h>

@implementation MyAppTests

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks grantAccessToContacts];
}

@end

Timeout

By default it tries to write the necessary entries to the TCC.db within 15 seconds. If that's not enough time, it just gives up and returns NO from the methods. If for any reason that is not enough time, you can change this default timeout via:

+ (void)setUp
{
    [super setUp];
    [JPSimulatorHacks setTimeout:30.0f];
}

Caveats

  • JPSimulatorHacks only works if unit test suite is run against real application target: Its Host Application is not set to None! See also: http://stackoverflow.com/a/28135995/598057
  • When using Xcode bots, sometimes the tests run into an timeout.
  • The keyboard helpers have been removed in 1.3.0

License (MIT)

Copyright (C) 2014 Johannes Plunien

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.