我有48条记录由FactoryGirl创建,记录使用序列,因此它们都是唯一的。
当我运行测试时,我会创建所有48条记录,其名称如下Skill_1至Skill_48。
当我运行后续测试时,我会创建另外48条记录,这些记录具有不同的新值,Skill_49到Skill_96
我真的希望我的第二次测试使用与第一次测试相同的数据集,但无法弄清楚如何操作。
我已经知道每次重新创建数据,但序列不会重置,因此每次运行时名称都不同
我在这里包含了我的代码
<Window x:Class="SliderApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SliderApplication"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10*" />
<RowDefinition />
</Grid.RowDefinitions>
<ListView Grid.Row="0" ItemsSource="{Binding Items}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ThicknessAnimation Storyboard.TargetProperty="Margin" From="0,0" To="500,0" Duration="0:0:15" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
</ListView>
<Button Grid.Row="1" Command="{Binding AddCommand}" />
</Grid>
</Window>
UNIT TEST在这里
# Factory
FactoryGirl.define do
factory :skill do
provisioned true
trait :skill do
skill true
end
trait :language do
language true
end
trait :qualification do
qualification true
end
trait :role do
role true
end
trait :personal_attribute do
personal_attribute true
end
sequence :name do |n|n
type = '(skill)'
if language
type = '(language)'
end
if qualification
type = '(qualification)'
end
if role
type = '(role)'
end
if personal_attribute
type = '(personal_attribute)'
end
"skill#{n} #{type}"
end
end
end
答案 0 :(得分:0)