MockUserDefaults

2.0.0

Mocking UserDefaults for tests
417-72KI/MockUserDefaults

What's New

2.0.0

2022-04-02T17:28:05Z

What's Changed

Full Changelog: 1.3.1...2.0.0

MockUserDefaults

Build Status GitHub release Platform Version GitHub license

MockUserDefaults is a simple replacement for NSUserDefaults/UserDefaults to make test easier.

Installation

SwiftPM (recommended)

.package(url: "https://github.com/417-72KI/MockUserDefaults.git", from: "2.0.0"),

CocoaPods

pod 'MockUserDefaults'

Usage

Objective-C

NSUserDefaults *userDefaults = [NSUserDefaults mockedUserDefaults];
[userDefaults setObject:@"string" forKey:@"key"];

XCTAssertEqualObjects([userDefaults objectForKey:@"key"], @"string");

Swift

let userDefaults: UserDefaults = .mocked
userDefaults.set("string", forKey: "key")

XCTAssertEqual(userDefaults.string(forKey: "key"), "string")

Demo

Create project

First time

make init_demo_app

After the first time

make demo_app

Usage

  1. open MockUserDefaultsDemo.xcworkspace
  2. Build and run app (⌘+R) in iPhone / iPad Simulator
  3. Add any keys and values
  4. Run test (⌘+U) in same simulator
  5. Re-run app (⌘+R) in same simulator
  6. You can see that the app isn't affected by the test.

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Sep 04 2022 01:06:33 GMT-0500 (GMT-05:00)