Continuous Integration and Continuous Delivery for Xamarin.iOS With VSTS

DZone 's Guide to

Continuous Integration and Continuous Delivery for Xamarin.iOS With VSTS

Jakub Jedryszek shares his experiences using Visual Studio Team Services to support Continuous Integration and Continuous Delivery for Xamarin.

· DevOps Zone ·
Free Resource

Visual Studio Team Services has great Continuous Integration and Continuos 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 a new version of the app to Hockey App. During the process of creating the 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.

Here are the issues I had that were not described anywhere online:

  • I couldn’t use the 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 a Xamarin project, I needed the 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 two tasks to build definition:

  1. Command Line task to run tests with mono and xUnit console runner.
  2. Publish Test Results task to display results in build summary.

First, install xUnit console runner NuGet package. To run tests, add a 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 the 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 they were run from VSTS while they passed 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 contain 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, a Delete Files task and delete everything from bin/* and obj/*.


The final build definition looks like this:

Azure Status VSTS build definition

Let me know if I missed some details; I would be happy to add them! Also, if you know a better way of doing this, let me know as well!

continuous delivery, continuous integration, devops, vsts, xamarin

Published at DZone with permission of Jacob Jedryszek , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}