AutoFakeItEasyDataAttribute可以为复杂对象填充测试数据,但是定制的fixture无法做到这一点。
创始人
2024-11-12 13:00:24
0

可以使用AutoDataAttribute来填充复杂对象的测试数据。同时,我们也可以使用Fixture customization来自定义测试数据并提供给需要的测试方法。例如:

using AutoFixture; using AutoFixture.AutoFakeItEasy; using AutoFixture.Xunit2;

public class MyTestClass { [Theory, AutoData] public void TestWithAutoDataAttribute(MyComplexObject obj) { // 测试方法使用AutoDataAttribute填充复杂对象的测试数据 }

[Theory, CustomizedAutoData]
public void TestWithCustomizedFixture(MyComplexObject obj)
{
    // 测试方法使用自定义的fixture填充复杂对象的测试数据
}

public class CustomizedAutoDataAttribute : AutoDataAttribute
{
    public CustomizedAutoDataAttribute()
        : base(() => new Fixture().Customize(new MyFixtureCustomization()))
    {
        // 创建自定义的fixture并提供给AutoDataAttribute
    }
}

public class MyFixtureCustomization : ICustomization
{
    public void Customize(IFixture fixture)
    {
        // 自定义测试数据
    }
}

}

在上面的示例代码中,我们使用AutoDataAttribute来填充复杂对象的测试数据,并使用CustomizedAutoDataAttribute来自定义测试数据。同时我们也创建了一个MyFixtureCustomization类来提供需要的自定义测试数据。

相关内容

热门资讯

透视实锤!aapoker透视脚... 透视实锤!aapoker透视脚本下载(透视)aapoker俱乐部靠谱吗,2025新版(有挂教程);1...
透视总结!wepoker私人局... 透视总结!wepoker私人局辅助挂,wepoker怎么挂飞机(详细私人局开挂视频);1.wepok...
透视科技!aapoker插件下... 透视科技!aapoker插件下载(透视)aapoker脚本怎么用,曝光教程(有挂规律);1、这是跨平...
透视安卓版!wepoker辅助... 透视安卓版!wepoker辅助器安装包,wepoker破解器激活码(详细辅助器)1、完成wepoke...
透视有挂!aapoker透视脚... 透视有挂!aapoker透视脚本(透视)aapoker辅助插件工具,揭秘教程(有挂细节)1、aapo...
透视实锤!wepoker辅助分... 透视实锤!wepoker辅助分析器,wepoker透视脚本视频(详细可以增加运气)1、实时wepok...
透视工具!aapoker发牌逻... 透视工具!aapoker发牌逻辑(透视)aapoker怎么拿好牌,必胜教程(有挂技巧)1、很好的工具...
透视代打!wepoker辅助工... 透视代打!wepoker辅助工具,wepoker透视脚本免费下载pc(详细透视苹果系统)进入游戏-大...
透视实锤!aapoker插件下... 透视实锤!aapoker插件下载(透视)aapoker安装包怎么使用,透明挂教程(有挂插件)1、玩家...
透视透视!wepoker提高好... 透视透视!wepoker提高好牌率,淘宝买wepoker透视有用吗(详细作弊方法)暗藏猫腻,小编详细...