Continuous Integration and Continuous Delivery for Xamarin.iOS with VSTS (Vistul Studio Team Services)
Visual Studio Team Services has great Continuous Integration and Continues Delivery support for Xamarin.
Recently I was configuring pipeline that would build the project, run unit tests (with xUnit), run UI tests (with Xamarin Test Cloud), and, if all tests pass, deploy new version of the app to Hockey App. During the process of creating VSTS build definition I encountered a few problems that I think are worth to share with you.
To make a basic build definition with building Xamarin.iOS project and deploying to Hockey App with VSTS+Xamarin check James Montemagno's Continuous Integration for iOS Apps with Visual Studio Team Services first.
The issues I had, that were not described anywhere online:
- I couldn't use "Visual Studio Test" task for running xUnit tests, because every build definition on VSTS can be executed by only one build agent, and to build Xamarin project I needed Mac build agent.
- How to run UI tests (with Xamarin Test Cloud) using the same build that would be later on deployed to Hockey App? Test Cloud requires init code that later on shouldn't be present in deployed app.
Running xUnit tests with Mac build agent
This requires adding 2 tasks to build definition:
- Command Line task - to run tests with mono and xUnit console runner.
- Publish Test Results task - to display results in build summary
First, install xUnit console runner NuGet package.
To run tests, add command line task with following settings:
- Tool: mono
- Arguments: packages/xunit.runner.console.2.1.0/tools/xunit.console.exe YourApp.UnitTests/bin/Debug/YourApp.UnitTests.dll -xml UnitTestsResults.xml
Remember to replace YourApp with your app name, and set the same xUnit runner version that you have installed.
To publish test results, add "Publish Test Results" task with the following settings:
- Test Result Format: XUnit
- Test Result Files: **/UnitTestsResults.xml
- Always run: true
Running Xamarin UI tests with Test Cloud before deploying to HockeyApp
The solution there is rather simple: build in Debug mode that has TEST_CLOUD preprocessor directive defined, run tests, and then build again in Release mode before deploying to Hockey App.
Delete files before build
For a while I couldn't figure out why my tests are not passing when run from VSTS while they pass on my machine. It turned out, VSTS was using old builds for tests. I am not sure about MacInCloud, but if you are using your own Build Agent running on your Mac the directories that contains binary files are not being cleaned up before next build automatically. To avoid using old builds, you can add, at the beginning of your pipeline, "Delete Files" task and delete everything from bin/* and obj/*.
The final build definition looks like that:
Let me know if I missed some details! I would be happy to add them! Also - if you know better way of doing that - let me know as well!