This code simplifies making Fake Settings App for setting notifications permissions (via FakeSettingsAppNotificationsApplicationPermissionSetter
)
You need to create Application target with any name and bundle id. It can be really anything that:
- Calls a specific function (
FakeSettingsAppMain
). - Has proper entitlements.
- Is a target dependency to your tests.
However, here is an example guide of how to make this app (steps may differ if you are using some other tools, e.g. if you don't use Cocoapods):
Add new target
Use simplest template (e.g.: Single View App), because all files of target will be replaced later.
Do not include any tests. Use Swift language.
You will see those files in your project:
Remove everything except Info.plist
.
Add main.swift
. Do not create bridging header if Xcode suggests you that. Contents:
import MixboxFakeSettingsAppMain
FakeSettingsAppMain(CommandLine.argc, CommandLine.unsafeArgv)
Add entitlements: Entitlements.entitlements.
So you should have those files in your target:
Set entitlements for target in your project settings:
Make sure that those storyboards that you created and then deleted are not used in project:
Add FakeSettingApp to target dependencies:
Expected result:
Add to your Podfile (link it as you like:
target 'FakeSettingsApp' do
pod 'MixboxFakeSettingsAppMain' # :path => '???' or '1.2.3' or :branch => 'master' or something else
end
pod install
In your tests DI container:
let applicationPermissionsSetterFactory = ApplicationPermissionsSetterFactory(
notificationsApplicationPermissionSetterFactory: FakeSettingsAppNotificationsApplicationPermissionSetterFactory(
fakeSettingsAppBundleId: "mixbox.Tests.FakeSettingsApp" // <--- bundle id you've chosen,
testFailureRecorder: testFailureRecorder
),
tccDbApplicationPermissionSetterFactory: tccDbApplicationPermissionSetterFactory // <--- is not a part of this documentation, other permissions
)
// This is an easy to use facade, to be used directly from tests.
permissions = applicationPermissionsSetterFactory.applicationPermissionsSetter(
bundleId: XCUIApplication().bundleID,
displayName: "My App", // <--- Name of your application (as on home screen)
testFailureRecorder: testFailureRecorder
)
Done! Use it like this: permissions.notifications.set(.allowed)