Build and Execute Xamarin.iOS Unit Test from Command Line

DinashDinash INMember
edited December 2016 in Xamarin.iOS

I have been trying to run the iOS unit test from command line. I am using Xamarin Studio on Mac for now, I Created a iOS Unit test project as follows

Add New Project --> iOS --> Tests --> Unit Test App

And added a simple Unit test class and its code snippets as shown below:

using System;
using NUnit.Framework;

namespace iOSUnitTest
{
    [TestFixture]
    public class iOSTestSample
    {
        public iOSTestSample()
        {
        }

        [Test]
        public void MySampleTest() {
            Assert.True(true);
        }

        [Test]
        public void MyFailerTest()
        {
            Assert.False(true);
        }
    }
}

From Xamarin Studio, I am able to run the application which deploys a app into simulator and execute the test cases. I am trying to automate it through a script.

Till now, I am able to get the Unit Test project build and install the app into the running simulator.

I am not sure how to automate the unit test execution once the app is installed.

Answers

  • DinashDinash INMember

    Found Blog on Building Xamarin App with Atlansian Bamboo - which covers how we can automate iOSUnitTest Project, It really helped.

    Used Touch.Server which can be checkout from Touch.Server Github Link

    And using below Command, was able to have the iOSUnitTest project being automated.

    mono --debug path/to/Touch.Server.exe \ --launchsim path/to/project/Debug/TestProject.app \ -autoexit \ -logfile=test-reports/TestProject.xml
    

    Also Refer https://spouliot.wordpress.com/2012/04/02/touch-unit-automation-revisited/

  • JoaoSilva.7604JoaoSilva.7604 ✭✭ GBUniversity ✭✭

    Hi @Dinash,

    Can you tell me how did you accomplish this?
    I did exactly as you said on the first post.
    I've already generated the Touch.Server.exe file and now I'm trying to use but I don't understand what and where is the *.app file... how do you get to generate it? is it from the ios unit test project?

    Thanks in advance

  • JoaoSilva.7604JoaoSilva.7604 ✭✭ GBUniversity ✭✭

    Got it, .app is the directory.
    Now I'm getting this:
    [mtouch stderr 17:04:51] warning MT0061: No Xcode.app specified (using --sdkroot), using the system Xcode as reported by 'xcode-select --print-path': /Applications/Xcode.app/Contents/Developer
    [mtouch stderr 17:04:52] error MT1212: Failed to create a simulator where type = SimDeviceType : com.apple.CoreSimulator.SimDeviceType.iPhone-4s and runtime = SimRuntime : 10.3 (14E269) - com.apple.CoreSimulator.SimRuntime.iOS-10-3.
    [mtouch stderr EOS]
    [mtouch stdout EOS]
    [12/04/2017 17:04:53] : System.Net.Sockets.SocketException (0x80004005): interrupted
    at System.Net.Sockets.Socket.Accept () [0x00039] in :0
    at System.Net.Sockets.TcpListener.AcceptTcpClient () [0x00016] in :0
    at SimpleListener.Start () [0x00003] in :0

    Do you have any idea?

    Thanks

  • JoaoSilva.7604JoaoSilva.7604 ✭✭ GBUniversity ✭✭

    Nvm, was missing --device=:v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-10-3,devicetype=com.apple.CoreSimulator.SimDeviceType.iPhone-7 on the properties of the Touch.Server.exe

  • NareshThandu.6490NareshThandu.6490 USMember

    Hello @JoaoSilva.7604
    I am getting a similar error to what you were getting. I have tried passing in the device and device type but still getting the same error.

    mono --debug /Users/nareshthandu/Downloads/Touch.Unit-master/Touch.Server/bin/Debug/Touch.Server.exe --launchsim .app \ --device=:v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-10-3 --devicetype=com.apple.CoreSimulator.SimDeviceType.iPhone-7 \ -autoexit \ -logfile=testresults_sim.log \ -verbose

    Can you please highlight if I am doing anything wrong.

    Thanks,
    Naresh

Sign In or Register to comment.