MbUnit-裂纹单元测试

MbUnit is a "better xUnit" that's used by a myraid of folks I respect, including James Avery, Patrick Cauldwell and Phil Haack. It's under very active development, even though I'd once wondered aloud if it was "abandonware." It's decidedly not and it's just got a new facelift to prove it.

MbUnit是一种“更好的xUnit”,我敬佩的许多人都在使用它,包括James Avery,Patrick Cauldwell和Phil Haack。 即使我曾经大声地想知道它是否是“放弃软件”,它仍处于非常活跃的开发中。 绝对不是,它只是进行了新的改容来证明这一点

Check out James Avery's Post called "I've seen the light and it is called MbUnitr."  I've asked around and everyone has nothing but nice things to say what MbUnit brings to the table. It's NOT just NUnit with some tweaks. James says it's "Unit testing on crack."

查看James Avery的帖子“我已经看过灯了,它叫做MbUnit r”。 我问了一下,每个人都说MbUnit带来了什么。 不仅仅是NUnit有一些调整。 詹姆斯说这是“裂缝的单元测试”。

Check this out...the test will get called four times, each time with different values passed in, some intending to cause and exception and others not. Very clean and certainly nicer than making a dozen methods like "NegativeTest54".

检查一下...测试将被调用四次,每次都传入不同的值,其中一些意图引起异常,而其他则不是。 非常干净,而且肯定比制作诸如“ NegativeTest54”之类的方法更好。

    1 [RowTest]

1 [行测试]

    2 [Row("James", "myemail@email.com")]

2 [行( “ James” , “ myemail@email.com” ))

    3 [Row("James", "", ExpectedException=typeof(InvalidUserException))]

3 [行( “ James” , “” ,ExpectedException = typeof (InvalidUserException))]

    4 [Row("", "myemail@emai.com", ExpectedException = typeof(InvalidUserException))]

4 [行( “” , “ myemail@emai.com” ,ExpectedException = typeof (InvalidUserException))]

    5 [Row("James", "mybademail.com", ExpectedException = typeof(InvalidUserException))]

5 [行( “ James” , “ mybademail.com” ,ExpectedException = typeof (InvalidUserException)))

    6 public void AddValidUser(string name, string email)

6公共无效AddValidUser(字符串名称,字符串电子邮件)

    7 {

7 {

    8     User u = new User();

8用户u = new User();

    9     u.Name = name;

9 u.Name =名称;

   10     u.Email = email;

10 u.Email =电子邮件;

   11 

11

   12     u.Save();

12 u.Save();

   13 

13

   14     User newUser = User.Retrieve(u.ID);

14用户newUser = User.Retrieve(u.ID);

   15     Assert.IsNotNull(newUser, "User not found");

15断言.IsNotNull(newUser, “未找到用户” );

   16     Assert.IsTrue(newUser.Name == u.Name, "Name not saved correctly");

16断言.IsTrue(newUser.Name == u.Name, “名称不正确保存”);

   17     Assert.IsTrue(newUser.Email == newUser.Email, "Email not saved correctly");

17断言.IsTrue(newUser.Email == newUser.Email, “电子邮件未正确保存” );

   18 }

18 }

It's even got a feature that will rollback database changes, keeping your database fresh after each test run. Sweet. I gotta do a show on Trends in Unit Testing...

它甚至具有将回滚数据库更改的功能,从而在每次测试运行后保持数据库的最新状态。 甜。 我要做一个关于单元测试趋势的节目...

翻译自: https://www.hanselman.com/blog/mbunit-unit-testing-on-crack

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值