MockUserDefaults 1.2.0

MockUserDefaults 1.2.0

Maintained by 417.72KI.



MockUserDefaults

Build Status Version Platform GitHub release Swift4.2 Swift5 GitHub license

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

Installation

CocoaPods

pod 'MockUserDefaults', '~> 1.2'

Carthage

github "417-72KI/MockUserDefaults" ~> 1.2

SwiftPM (Swift5 only)

.package(url: "https://github.com/kylef/Commander.git", .upToNextMajor(from: "1.2.0")),

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

Dependencies

Tool

  • CocoaPods
    • Bundler
  • Carthage
    • Homebrew
  • XcodeGen
    • Mint
      • Homebrew
  • Fastlane
    • Bundler

Library

  • R.swift
  • RxSwift
  • RxDataSources
  • Nimble
  • Quick

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.