Skip to content

How to use mock implementation in UIAppDelegate when running UI tests #65

Answered by mbrandonw
vrutberg asked this question in Q&A
Discussion options

You must be logged in to vote

Since you are using the dependency at the very root level entry point of the application, I think the only thing you can do is check for the environment variable inside the liveValue in order to provide a mock implementation:

extension MyServiceKey: DependencyKey {
  static var liveValue: any MyService {
    if ProcessInfo.processInfo.arguments.contains("useMockedService") {
      return MockedMyService()
    } else {
      return LiveMyService()
    }
  }
}

If you did not use @Dependency at such a root level you would have more options. For example, in the Standups app we built, the entry point of the app creates the root AppView, which uses @Dependency. That gives us enough wiggle room …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@vrutberg
Comment options

@nashysolutions
Comment options

@iampatbrown
Comment options

@mbrandonw
Comment options

Answer selected by vrutberg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants