title: Xamarin.Forms unit testing of a View page fail with static resources
body: <p>I'm trying to build a unit test for a View page in my XF application, although I can't really find any detail around this on the web, I've gotten Xamarin.Forms.Mocks package installed, but I'm running into a snag.</p>
  
  <p>Take my View page:</p>
  
  <pre><code>public partial class WelcomePage : ContentPage
  {
      public WelcomePage()
      {
          InitializeComponent();
          NavigationPage.SetHasNavigationBar(this, false);
          WelcomeTransaction();
      }
  
      public async void WelcomeTransaction()
      {
          ButtonRegister.Opacity = 0;
          ButtonRegisterNewDevice.Opacity = 0;
  
          await Task.WhenAny&lt;bool&gt;
          (
            ButtonRegister.FadeTo(1, 1000, Easing.SinIn),
            ButtonRegisterNewDevice.FadeTo(1, 1000, Easing.SinIn)
          );
      }
  }
  </code></pre>
  
  <p>Very simple class.</p>
  
  <p>My issue is that my tests keep failing on "InitializeComponent" because I have static resources attached.</p>
  
  <p>My XAML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms" prism:ViewModelLocator.AutowireViewModel="True" x:Class="Sandbox.Views.WelcomePage"&gt;
      &lt;ContentPage.Content&gt;
          &lt;AbsoluteLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"&gt;
              &lt;Image Source="splashscreen.png" Aspect="Fill" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 1, 1, 1" /&gt;
              &lt;StackLayout Padding="15" Spacing="1" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="1, 1, 1, 0.5" VerticalOptions="EndAndExpand"&gt;
                  &lt;Button x:Name="ButtonRegister" AutomationId="ButtonRegister" Text="REGISTER" Style="{StaticResource ButtonNormal}" Command="{Binding RegisterCommand}"&gt;
                  &lt;/Button&gt;
                  &lt;Button x:Name="ButtonRegisterNewDevice" AutomationId="ButtonRegisterNewDevice" Text="REGISTER A NEW DEVICE" Style="{StaticResource ButtonHighlighted}" Command="{Binding RegisterNewDeviceCommand}" /&gt;
              &lt;/StackLayout&gt;
          &lt;/AbsoluteLayout&gt;
      &lt;/ContentPage.Content&gt;
  &lt;/ContentPage&gt;
  </code></pre>
  
  <p>My unit test:</p>
  
  <pre><code>[TestFixture]
  public class ViewTest
  {
      private Views.WelcomePage _welcome;
  
      [SetUp]
      public void BeforeEach()
      {
          Xamarin.Forms.Mocks.MockForms.Init();
      }
  
      [Test]
      [Category("Welcome Page View")]
      public void Can_Call_Constructor()
      {
          _welcome = Substitute.For&lt;Views.WelcomePage&gt;();
  
      }
  }
  </code></pre>
  
  <p>I'm using NSubstitute, Xamarin.Forms.Mock, Moq and NUnit.</p>
  
  <p>I'm trying to do this as part of a learning scenario, and would appreciate any input.</p>