KellyTheDev
KellyTheDev

Reputation: 901

Unit testing a Xamarin Forms Android specific code project

I'm running into an issue where I've done a Xamarin.Forms Application.

Currently, I'm trying to Unit test an Android Service.

So currently this means I've done the following at this point:

  1. default Xamarin forms application with iOS project deleted
  2. Basic Forms in the PCL created
  3. Have styles created in Xamarin.Forms PCL
  4. Have basic theme in Xamarin.Forms.Droid project

After doing that, I've created Xamarin UITest Android Project

Now, I've added a reference to the Xamarin Forms.Droid Project

Every time I launch the unit test, which has to run in the Android emulator, it fails to find the theme.

within the app.xml that resides in the PCL

<Application.Resources>
    <!-- Application resource dictionary -->
    <ResourceDictionary>
        <Color x:Key="BackgroundGlobal">#ff333333</Color>
        <Color x:Key="MidGradient">#ff0d0d0d</Color>
        <Color x:Key="BottomGradient">Black</Color>
        <Color x:Key="MenuTextColor">Azure</Color>
        <Style TargetType="ImageCell" x:Key="Clicky">
            <Setter Property="TextColor" Value="{StaticResource  MenuTextColor}"/>
            <Setter Property="DetailColor" Value="Aqua"/>
        </Style>
    </ResourceDictionary>
</Application.Resources>

within the Xamarin.Forms.Droid Resource\Values\strings.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
        <style name="MainTheme" parent="MainTheme.Base">
        </style>

        <!-- Base theme applied no matter what API -->
        <style name="MainTheme.Base" parent="Theme.AppCompat">
            <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
            <item name="windowNoTitle">true</item>
            <!--We will be using the toolbar so no need to show ActionBar-->
            <item name="windowActionBar">false</item>
            <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
            <!-- colorPrimary is used for the default action bar background -->
            <item name="colorPrimary">#2196F3</item>
            <!-- colorPrimaryDark is used for the status bar -->
            <item name="colorPrimaryDark">#1976D2</item>
            <!-- colorAccent is used as the default value for colorControlActivated
     which is used to tint widgets -->
            <item name="colorAccent">#FF4081</item>
            <!-- You can also set colorControlNormal, colorControlActivated
     colorControlHighlight and colorSwitchThumbNormal. -->
            <item name="windowActionModeOverlay">true</item>
            <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
       </style>   
       <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
            <item name="colorAccent">#FF4081</item>
       </style>
   </resources>

I currently get the following:

Severity    Code    Description Project File    Line    Suppression State Error 
Error: No resource found that matches the given name (at 'theme' with value '@style/MainTheme').    Xamarin.Forms.Droid.Tests   C:\dev\git\example\Xamarin.Forms.Droid.Tests\obj\Debug\android\manifest\AndroidManifest.xml 9   

Upvotes: 0

Views: 440

Answers (1)

York Shen
York Shen

Reputation: 9084

No resource found that matches the given name (at 'theme' with value '@style/MainTheme').

Resource\Values\strings.xml just provides a text string with optional text style and formatting for your application. There are three types of resources that can provide a string for your application: String, String Array and Quantity Strings(Plurals).

You should put your theme style in Resource\Values\styles.xml instead of styles.xml, like this.

For more information about Style Resource, you could read this document.

Upvotes: 1

Related Questions