mardi 17 septembre 2019

How to run Xamarin Forms to Xunit tests

i need to know my device ID in test through Plugin.DeviceInfo library packcage. But when i run tests they don't pass because device id is null. Here is code: Test.cs

using TestApp;
using Xunit;
using Xamarin.Forms.Mocks;

namespace XUnitTestProject1 {
    public class UnitTest1 {
        [Fact]
        public void FirstTest() {
            var app = new App();
            var loginMock = new LoginPageVM();
            var result = loginMock.Login();

            Xunit.Assert.NotNull(result);
            MockForms.Init();
        }
    }
}

LoginPageVM.cs

using Plugin.DeviceInfo;

namespace TestApp {
    public class LoginPageVM {
        public string Login() {
            var x = CrossDeviceInfo.Current.Id;
            return x;
        }   
    }
}

SO how can i know the device id, without running application

Aucun commentaire:

Enregistrer un commentaire