对Xamarin Forms Android特定代码项目进行单元测试 [英] Unit testing a Xamarin Forms Android specific code project
问题描述
我遇到了完成Xamarin.Forms应用程序的问题.
I'm running into an issue where I've done a Xamarin.Forms Application.
当前,我正在尝试对Android服务进行单元测试.
Currently, I'm trying to Unit test an Android Service.
因此,目前这意味着我目前已完成以下操作:
So currently this means I've done the following at this point:
- 已删除iOS项目的默认Xamarin表单应用程序
- 在PCL中创建了基本表单
- 具有在Xamarin.Forms PCL中创建的样式
- 在Xamarin.Forms.Droid项目中具有基本主题
这样做之后,我创建了Xamarin UITest Android项目
After doing that, I've created Xamarin UITest Android Project
现在,我已经添加了对Xamarin Forms.Droid项目的引用
Now, I've added a reference to the Xamarin Forms.Droid Project
每次启动必须在Android模拟器中运行的单元测试时,它都找不到主题.
Every time I launch the unit test, which has to run in the Android emulator, it fails to find the theme.
位于PCL中的app.xml中
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>
在Xamarin.Forms.Droid Resource \ Values \ strings.xml中
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>
我目前得到以下信息:
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
推荐答案
未找到与给定名称匹配的资源(在主题"处,值为"@ style/MainTheme").
No resource found that matches the given name (at 'theme' with value '@style/MainTheme').
Resource\Values\strings.xml
只是为您的应用程序提供带有可选文本样式和格式的文本字符串.可以为您的应用程序提供字符串的三种类型的资源:String
,String Array
和Quantity Strings(Plurals)
.
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)
.
您应该将主题样式放在Resource\Values\styles.xml
而不是styles.xml
中,例如此.
You should put your theme style in Resource\Values\styles.xml
instead of styles.xml
, like this.
有关Style Resource
的更多信息,您可以阅读文档.
For more information about Style Resource
, you could read this document.
这篇关于对Xamarin Forms Android特定代码项目进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!