Does Xamarin Enable Unit Testing?

CarlCCarlC GBMember
edited April 2016 in Visual Studio

Dear all
Im new to this forum and was hoping someone could clarify a few questions about Xamarin for Visual Studio.I was thinking of downloading Xamarin VS to primarily make Android apps(might make iOS) and was looking on the Xamarin Visual Studio site to see if when developing mobile apps using Xamarin i could get access to mobile specific parts e.g GPS,accelorometer etc but its not entirely clear.
Also could Xamarin be used as a unit testing framework?

Many thanks for any helpful replies.

Answers

  • VictorGarciaAprea.9996VictorGarciaAprea.9996 Xamurai USXamarin Team Xamurai

    Hi Carlc,

    Yes, you can use Xamarin to develop native Android apps, you will have access to native APIs to access GPS, etc.

    On the unit testing framework front, there are multiple frameworks you can use with Xamarin. There are also UI test frameworks like UITest (https://developer.xamarin.com/guides/testcloud/uitest/) which are very helpful.

    Please give this a try and let us know if you have any more specific questions.

  • XamarinersXamariners ✭✭ SGBeta ✭✭

    Hi,

    I just put out a nuget package 'SpecFlow.Xamarin.Forms' that facilitates unit testing in Xamarin.forms in the console runner (ie for visual studio, team city, etc). It makes it easy to test your ViewModels / Commands/ Internal Navigation.
    As the host would be the test app, you won't have a hook to the device services, but you can mock them easily using dependency injection.

    we do provide a hook for this in the testing framework, in this file:

    public class DemoAppTest : TestApp
        {
            protected override void SetViewModelMapping()
            {
                TestViewFactory.EnableCache = false;
    
                // register your views / viewmodels below
                RegisterView<MainPage, MainViewModel>();
                RegisterView<AnotherPage, AnotherViewModel>();
            }
    
            protected override void InitialiseContainer()
            {
                // add any dependency injection registration goes  here
                //Resolver.Instance.Register<TInterface, TType>();
                base.InitialiseContainer();
            }
        }
    

    On the 'InitialiseContainer' method, add your services implementations for testing, as per the comment.

    You can find the step by step tutorial here.

  • BenBishopBenBishop ✭✭ USBeta ✭✭

    I'm adding this for anyone that may come across this in the future...

    I did a video series demonstrating on to test your core code with Nunit, FakeItEasy, Autofixture, etc...
    https://brax.tv/series/real-world-testing-with-xamarin-forms/unit-test-with-red-green-blue-tdd

    Might be useful

  • ChrisColeTechChrisColeTech ✭✭✭ USMember ✭✭✭

    it is not possible to do unit testing in xamarin ios from within visual studio

Sign In or Register to comment.