nunit单元测试_使用NUnit和使用外部文件相关性进行单元测试的更好方法

nunit单元测试

nunit单元测试

Great stuff on using NUnit in conjunction with external files from Patrick Cauldwell.  It's one of those "Doh!" things that I've always MEANT to do, but somehow ended up using Pre- and Post-Build events instead.  I MUCH prefer Patrick's method.  It's much cleaner and it allows the once-external file to LIVE with the test.

关于将NUnit与Patrick Cauldwell的外部文件结合使用的好东西。 这就是那些“ Doh!” 我一直很想做的事情,但是最终还是使用了Pre-和Post-Build事件。 我更喜欢帕特里克的方法。 它更加干净,并且可以将曾经是外部文件的文件与测试一起使用。

        [SetUp] public void SetUp()
        {
            Assembly a = Assembly.GetExecutingAssembly();
            using (Stream s = a.GetManifestResourceStream("MyNameSpace.something.txt"))
            {
                using (StreamReader sr = new StreamReader(s))
                {
                    using (StreamWriter sw = File.CreateText(webConfigPath))
                    {
                        sw.Write(sr.ReadToEnd());
                        sw.Flush();
                    }
                }
            }
        }
        [TearDown] public void TearDown()
        {
            if(File.Exists(webConfigPath))
            {
                File.Delete(webConfigPath);
            }
        }

[SetUp] public void SetUp()
{
程序集a = Assembly.GetExecutingAssembly();
使用(Stream s = a.GetManifestResourceStream( “ MyNameSpace.something.txt” ))
{
使用(StreamReader sr = new StreamReader(s))
{
使用(StreamWriter sw = File.CreateText(webConfigPath))
{
sw.Write(sr.ReadToEnd());
sw.Flush();
}
}
}
}
[TearDown] public void TearDown()
{
如果(File.Exists(webConfigPath))
{
File.Delete(webConfigPath);
}
}

翻译自: https://www.hanselman.com/blog/using-nunit-and-a-better-way-to-unit-test-with-external-file-dependancies

nunit单元测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值