0

Expensify Windows Phone Test Framework を使い始めたばかりですが、Windows Phone 7.1 の自動テストの要件に非常によく合っているようです。画面上の通常のボタンをトリガーすることはできますが、ApplicationBar ボタンのいずれかをトリガーすることはできません。

このテスト ページの XAML は ...

<phone:PhoneApplicationPage x:Class="SampleApp1.MainPage"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                        xmlns:AppBarUtils="clr-namespace:AppBarUtils;assembly=AppBarUtils"
                        FontFamily="{StaticResource PhoneFontFamilyNormal}"
                        FontSize="{StaticResource PhoneFontSizeNormal}"
                        Foreground="{StaticResource PhoneForegroundBrush}"
                        SupportedOrientations="Portrait"
                        Orientation="Portrait"
                        mc:Ignorable="d"
                        d:DesignWidth="480"
                        d:DesignHeight="768"
                        shell:SystemTray.IsVisible="True"
                        DataContext="{Binding Main, Source={StaticResource Locator}}">

<!--LayoutRoot contains the root grid where all other page content is placed-->
<Grid x:Name="LayoutRoot"
      Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel"
                Grid.Row="0"
                Margin="24,24,0,12">
        <TextBlock x:Name="ApplicationTitle"
                   Text="{Binding ApplicationTitle}"
                   Style="{StaticResource PhoneTextNormalStyle}" />
        <TextBlock x:Name="PageTitle"
                   Text="{Binding PageName}"
                   Margin="-3,-8,0,0"
                   Style="{StaticResource PhoneTextTitle2Style}" />
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentGrid"
          Grid.Row="1">
        <StackPanel Margin="24,20,0,123" Orientation="Vertical">
            <TextBlock Text="{Binding Welcome, Mode=OneWay}" 
                       Style="{StaticResource PhoneTextNormalStyle}"
                       HorizontalAlignment="Center" VerticalAlignment="Center"
                       Margin="6,0,19,0" TextWrapping="Wrap" Width="431" />
            <TextBlock Text="Enter first number" 
                       HorizontalAlignment="Left" VerticalAlignment="Top"
                       Margin="6,20,0,0" TextWrapping="Wrap" />
            <TextBox TextChanged="OnTextBoxTextChanged"
                     Text="{Binding EnteredAmount1, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
                     x:Name="txtValue1" 
                     HorizontalAlignment="Left" Height="72" VerticalAlignment="Top" Width="456" 
                     TextWrapping="Wrap" InputScope="Number"/>
            <TextBlock Text="Enter second number" 
                       HorizontalAlignment="Left" VerticalAlignment="Top" 
                       Margin="6,0,0,0" TextWrapping="Wrap" />
            <TextBox TextChanged="OnTextBoxTextChanged"
                     Text="{Binding EnteredAmount2, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
                     x:Name="txtValue2" 
                     HorizontalAlignment="Left" Height="72" VerticalAlignment="Top" Width="456" 
                     TextWrapping="Wrap" InputScope="Number"/>
            <TextBlock Text="Result" 
                       HorizontalAlignment="Left" VerticalAlignment="Top"
                       Margin="6,20,0,0" TextWrapping="Wrap"/>
            <TextBlock Text="{Binding Total, Mode=OneWay}" 
                       HorizontalAlignment="Left" VerticalAlignment="Top" 
                       Margin="15,0,0,0" TextWrapping="Wrap" 
                       Width="422" Height="45"/>
            <Button x:Name="btnAdd" Command="{Binding AddCommand}" Content="Add" Margin="240,0,0,0" />
        </StackPanel>
    </Grid>
</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="False">
        <shell:ApplicationBarIconButton x:Name="AddAppBarBtn" IconUri="/Images/ApplicationBar.Check.png" Text="add"></shell:ApplicationBarIconButton>
        <shell:ApplicationBarIconButton x:Name="SubtractAppBarBtn" IconUri="/Images/ApplicationBar.Cancel.png" Text="subtract"></shell:ApplicationBarIconButton>

    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

<i:Interaction.Behaviors>
    <AppBarUtils:AppBarItemCommand Id="add" Command="{Binding AddCommand}"/>
    <AppBarUtils:AppBarItemCommand Id="subtract" Command="{Binding SubtractCommand}"/>
</i:Interaction.Behaviors>


<i:Interaction.Triggers>
    <AppBarUtils:AppBarItemTrigger Type="Button" Id="add" Text="add" />
    <AppBarUtils:AppBarItemTrigger Type="Button" Id="subtract" Text="subtract" />
</i:Interaction.Triggers>

</phone:PhoneApplicationPage>

SpecFlow 機能は次のように定義されています ...

Scenario: AppBar Add Two Numbers
Given my app is uninstalled
And my app is installed
And my app is running within 20 seconds
Then I enter "34" into the control "txtValue1"
Then I enter "23" into the control "txtValue2"
Then I press the control "AddAppBarBtn"

Scenario: Button Add Two Numbers
Given my app is uninstalled
And my app is installed
And my app is running within 20 seconds
Then I enter "34" into the control "txtValue1"
Then I enter "23" into the control "txtValue2"
Then I press the control "btnAdd"

ButtonAddTwoNumbers シナリオは完全に機能します。AppBarAddTwoNumbers はテキスト ボックスの値を入力しますが、ボタンを押すことを拒否します。エラーは「'AddAppBarBtn' を制御するためにフォーカスを設定できませんでした」です。

これに関する助けをいただければ幸いです。

4

1 に答える 1

0

レベルが高すぎると思います。個人的には、長期的には常に変更が必要な脆弱なテストにつながるだけなので、通常は UI 自体をテストしません。代わりに、通常は ViewModel に行き着きます。

したがって、txtValue1 が EnteredAmount1 にバインドされ、txtValue2 が EnteredAmount2 で、AddAppBarBtn が AddCommand であるとすると、ビジネス ロジックを次のようにテストできます。

Scenario: AppBar Add Two Numbers
Given I enter 34 into Amount1
And I enter 23 into Amount2 
When I add them  #Calls AddCommand
Then Total should be 57

これは、UI を非常に簡単に再設計できることを意味します。たとえば、テキスト ボックスの代わりにスライダーを使用したい場合、上記のロジック テストに変更はありません。

さらに、UI 機能を別の機能としてテストすることもできます

Scenario: Check startup
Given my app is uninstalled
When my app is installed
Then my app should be running within 20 seconds

本当に必要な場合は、バインディングも確認できます

 Scenario: Check bindings
 Given I enter 34 into Amount1
 Then control txtValue1 should be 34

このようにして、テストをアプリケーションの小さなチャンクに分割し、よりターゲットを絞った失敗を自分自身に与えることができます。これは、問題を追跡するときに非常に役立ちます。

于 2013-01-21T15:38:34.147 に答える