Test Plans in Xcode allow us to run Unit Tests and UI Tests with different configurations multiple times. It is very convenient and is very quick.
Available Configuration Options
Each Test Plan can have a different configuration.
- Launch arguments and Launch environment variables,
- Language and region,
- Sanitizers and Main Thread Checker,
- Simulated location,
- UI Testing Screenshots and attachment lifetime configuration,
If you are interested in video lessons on how to write Unit tests and UI tests to test your Swift mobile app, check out this page: Unit Testing Swift Mobile App
Creating a New Test Plan
To create a new test plan we will need to edit the current project scheme and convert current Test Targets to use Test Plans.
Once you click on Convert to use Test Plans button, you will be presented with an option window.
If this is your first time creating a Test Plan, then you will choose the very first option “Create Test Plan from scheme”. If you already have a test plan created earlier, then you can choose the last option and create a test plan for this project out of an existing test plan on your disk.
Then give your test plan a name and save it in your project.
Creating a New Configuration
Once you have created a new Test Plan, you will see a new file added to your project with .xctestplan file extension. Double-click to open this file and then click on the Configurations tab as it is illustrated in the image below.
Have a look at these configuration options. Here you can provide custom configuration options and save. You can create more than one configuration for the current test plan and each configuration with different options.
To create a new configuration click on the “+” button in the bottom left corner.
You can give each Test Plan configuration a different name and different options. In my project, for example, I have created two configurations. Each configuration contains a different environment variable to make my mobile app use a different test server URL. This will make my UI Tests run a mobile app and make it work with a different test server.
Run UI Tests with Selected Test Plan Configuration
To run UI Tests with one of created Test Plan configurations, you can do Option + Click on the test diamond in your test code and run a test method with one of the available configurations.
I hope this tutorial was of some value to you. If you are interested in video lessons that show how to create and use test plans as well as how to follow the Test-Driven Development(TDD) process to build a mobile app with Swift and how to write UI tests for it, then have a look at this series of video lessons I have recorded – Unit Testing Swift Mobile Apps.