Choosing the Right Test Scope in Swift: UI, Unit, or End-to-End?

Hello, everyone!

I'm currently working on creating tests for a study project in Swift. My current task is to create a test to check if a file is saved correctly.

The workflow in the app is as follows:

Launch the app.

  1. Open a file within the app.
  2. Modify the file.
  3. Save it inside the app.
  4. Save it to the Files app.

I need to verify if the saved file in the Files app is identical to a base file stored in the app bundle.

Initially, I thought I could solve this by creating a UI test, which I've already implemented up to a certain point. The UI test successfully navigates through the workflow steps until it's time to compare the saved file with the base file.

The problem is that I cannot open a saved file from the Files app in a UI test because it operates in a sandboxed environment and cannot interact with external app scopes.

So, my question is: What should I do in this case?

Would it be better to create a unit test specifically for testing the save function and ensure the UI test only verifies if the expected filename exists in the Files app?

I would prefer an end-to-end (E2E) test that covers the entire workflow, but it seems Swift splits tests into Unit and UI test groups, making this approach less straightforward.

Any suggestions or best practices would be greatly appreciated!

Choosing the Right Test Scope in Swift: UI, Unit, or End-to-End?
 
 
Q