MockUserDefaults
is a simple replacement for NSUserDefaults
/UserDefaults
to make test easier.
.package(url: "https://github.com/417-72KI/MockUserDefaults.git", from: "2.4.0"),
pod 'MockUserDefaults'
NSUserDefaults *userDefaults = [NSUserDefaults mockedUserDefaults];
[userDefaults setObject:@"string" forKey:@"key"];
XCTAssertEqualObjects([userDefaults objectForKey:@"key"], @"string");
let userDefaults: UserDefaults = .mock
userDefaults.set("string", forKey: "key")
XCTAssertEqual(userDefaults.string(forKey: "key"), "string")
make init_demo_app
make demo_app
- open
MockUserDefaultsDemo.xcworkspace
- Build and run app (⌘+R) in iPhone / iPad Simulator
- Add any keys and values
- Run test (⌘+U) in same simulator
- Re-run app (⌘+R) in same simulator
- You can see that the app isn't affected by the test.