{"id":35000,"date":"2018-01-19T13:32:24","date_gmt":"2018-01-19T18:32:24","guid":{"rendered":"https:\/\/blog.xamarin.com\/?p=35000"},"modified":"2018-01-19T13:32:24","modified_gmt":"2018-01-19T18:32:24","slug":"running-xamarin-ios-unit-tests-visual-studio-team-services","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/running-xamarin-ios-unit-tests-visual-studio-team-services\/","title":{"rendered":"Running Xamarin.iOS Unit Tests in Visual Studio Team Services"},"content":{"rendered":"<p>\t\t\t\tIn previous posts, we&#8217;ve discussed how to <a href=\"https:\/\/montemagno.com\/building-xamarin-ios-apps-in-team-services-vsts-with-hosted-macos-agents\/\">set up continuous integration for your Xamarin.iOS applications inside Visual Studio Team Services(VSTS)<\/a> using the new Hosted macOS Agent. Building the application is only part of the full solution, though, as we want to fully test the logic of our application. We can test our app\u2019s user interface with App Center Test, we can test our business logic with test runners, but how do we test platform specific functionality?<\/p>\n<p>We can accomplish this by leveraging the Touch.Server on iOS to run our platform-specific tests on a real device or simulator. This is great for the platform-specific code of an application and ideal for testing libraries, such as plugins, that are purely application-specific code. In this post, we&#8217;ll show you how to set up continuous unit tests for <a href=\"https:\/\/github.com\/jamesmontemagno\/SettingsPlugin\">SettingsPlugin<\/a> projects in VSTS.<\/p>\n<h2>Getting started<\/h2>\n<p>Download the <a href=\"https:\/\/github.com\/prashantvc\/Touch.Server\/releases\/\">Touch.Server.exe<\/a> to your project folder, a small tool originally built by <a href=\"https:\/\/github.com\/rolfbjarne\">Rolf Kvinge<\/a> on the Xamarin.iOS team (this can be automated with a script later on). Touch.Server will make it easier to execute tests on a Simulator or a Device and pull tests results on the build machine for further processing.<\/p>\n<p>Set the <code>NUNIT_ENABLE_XML_OUTPUT<\/code> and <code>NUNIT_SKIP_LOG_HEADER<\/code> environment variables to <strong>&#8220;TRUE&#8221;<\/strong> in Additional <em>mtouch<\/em> arguments in the Unit test project\u2019s project options\/iOS build.<\/p>\n<p><figure id=\"attachment_35007\" aria-labelledby=\"figcaption_attachment_35007\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"wp-image-35007\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Screenshot-2017-12-28-10.53.48_preview.png\" alt=\"\" width=\"750\" height=\"564\" \/><figcaption id=\"figcaption_attachment_35007\" class=\"wp-caption-text\">iOS Project Properties<\/figcaption><\/figure><\/p>\n<p>The iOS test project generates an excellent test result report by default; however, it is not compatible with the VSTS build system. Setting <code>NUNIT_ENABLE_XML_OUTPUT<\/code> to <strong>&#8220;TRUE&#8221;<\/strong> generates the test results compatible to the VSTS build system, and <code>NUNIT_SKIP_LOG_HEADER<\/code> removes redundant headers in the results file.<\/p>\n<h2>Setting up Build Configuration in VSTS<\/h2>\n<p>Add the following two additional steps to iOS build process defined on <a href=\"https:\/\/montemagno.com\/building-xamarin-ios-apps-in-team-services-vsts-with-hosted-macos-agents\/\">James Montemagno&#8217;s blog<\/a>.<\/p>\n<h3>1) Shell Script<\/h3>\n<p>In this step, configure the shell script to configure test environment ie., set up the iOS simulator, auto execute tests, and provide a location to store test results.<\/p>\n<p><figure id=\"attachment_35004\" aria-labelledby=\"figcaption_attachment_35004\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"wp-image-35004\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Screenshot-2017-12-27-20.37.48_preview.png\" alt=\"\" width=\"750\" height=\"421\" \/><figcaption id=\"figcaption_attachment_35004\" class=\"wp-caption-text\">Shell Script Config<\/figcaption><\/figure><\/p>\n<p>Here is the simple script that does it all &#8211;<\/p>\n<pre><code>\n#!\/bin\/sh\necho 'Output path = ' $1\nTEST_RESULT=$1\/test_results.xml\necho 'Delete test result'\nrm -rf $TEST_RESULT\nmono --debug unit-test-tools\/Touch.Server.exe \\\n--launchsim  \\\n-autoexit \\\n-skipheader \\\n-logfile=$TEST_RESULT \\\n--verbose \\\n--device=\":v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-11-2,devicetype=com.apple.CoreSimulator.SimDeviceType.iPhone-SE\"\n<\/pre>\n<p><\/code><\/p>\n<p>&nbsp;<\/p>\n<h3>2) Publish Test Results<\/h3>\n<p>This is a final step in the process. Once test execution completes, the build process will look for the <code>test_results.xml<\/code> and publish!<\/p>\n<p><figure id=\"attachment_35005\" aria-labelledby=\"figcaption_attachment_35005\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"wp-image-35005\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Screenshot-2017-12-27-20.47.33_preview.png\" alt=\"\" width=\"750\" height=\"473\" \/><figcaption id=\"figcaption_attachment_35005\" class=\"wp-caption-text\">Publish Results<\/figcaption><\/figure><\/p>\n<p>Note that VSTS will report the build successful even when there are failed tests in the published results. This issue is being discussed <a href=\"https:\/\/github.com\/Microsoft\/vsts-tasks\/issues\/1268\">on GitHub<\/a>.<\/p>\n<h2>Conclusion<\/h2>\n<p>VSTS will report the summary after every successful\/failed build process with the test results:<\/p>\n<p><figure id=\"attachment_35006\" aria-labelledby=\"figcaption_attachment_35006\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"wp-image-35006\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Screenshot-2017-12-27-21.08.14_preview.png\" alt=\"\" width=\"750\" height=\"336\" \/><figcaption id=\"figcaption_attachment_35006\" class=\"wp-caption-text\">Build Summary<\/figcaption><\/figure><\/p>\n<h3>Learn More<\/h3>\n<p>Be sure to read through <a href=\"https:\/\/developer.xamarin.com\/guides\/ios\/deployment,_testing,_and_metrics\/touch.unit\/\">Xamarin.iOS Unit Testing documentation<\/a> to see how to setup your apps for testing. Then be sure to see how to set up continuous integration and deployment with <a href=\"https:\/\/docs.microsoft.com\/en-us\/vsts\/build-release\/apps\/mobile\/xamarin?tabs=vsts\">Visual Studio Team Services with the Quick Start guide<\/a>.<\/p>\n<p><em><a href=\"https:\/\/forums.xamarin.com\/118239\/running-xamarin-ios-unit-tests-in-visual-studio-team-services\/\">Discuss this post in the Xamarin Forums.<\/a><\/em>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In previous posts, we&#8217;ve discussed how to set up continuous integration for your Xamarin.iOS applications inside Visual Studio Team Services(VSTS) using the new Hosted macOS Agent. Building the application is only part of the full solution, though, as we want to fully test the logic of our application. We can test our app\u2019s user interface [&hellip;]<\/p>\n","protected":false},"author":558,"featured_media":35007,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[6,4],"class_list":["post-35000","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-ios","tag-xamarin-platform"],"acf":[],"blog_post_summary":"<p>In previous posts, we&#8217;ve discussed how to set up continuous integration for your Xamarin.iOS applications inside Visual Studio Team Services(VSTS) using the new Hosted macOS Agent. Building the application is only part of the full solution, though, as we want to fully test the logic of our application. We can test our app\u2019s user interface [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/35000","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/558"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=35000"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/35000\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=35000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=35000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=35000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}