This has to be one of the coolest and most functional things I have seen in a long time! I use NUnit every single day at work, I have written tons of unit tests. Whats most painful for unit tests is the code duplication, you have to duplicate so much code you end up with this massive hunkin test fixture with hundreds of tests that do nearly the same thing but slightly different. Some of them expect exceptions and some of them dont, it just ends up being a mess.
Welcome to MbUnit, very very cool, I will borrow a code snippet below from
Scott Hansleman to show you why:
1 [RowTest]
2 [Row("James", "myemail@email.com")]
3 [Row("James", "", ExpectedException=typeof(InvalidUserException))]
4 [Row("", "myemail@emai.com", ExpectedException = typeof(InvalidUserException))]
5 [Row("James", "mybademail.com", ExpectedException = typeof(InvalidUserException))]
6 public void AddValidUser(string name, string email)
7 {
8 User u = new User();
9 u.Name = name;
10 u.Email = email;
11
12 u.Save();
13
14 User newUser = User.Retrieve(u.ID);
15 Assert.IsNotNull(newUser, "User not found");
16 Assert.IsTrue(newUser.Name == u.Name, "Name not saved correctly");
17 Assert.IsTrue(newUser.Email == newUser.Email, "Email not saved correctly");
18 }
So if you still dont get it take a look closer, they have written a rather generic unit test here, no big deal. Where the beauty comes in is that it takes parameters! You specify your test data in your attributes and you also specify the expected behavior of the test, this is absolutely brilliant!! So instead of four seperate NUnit tests its 4 unit tests condensed into one unit test block. As Scott would put it, "NUnit on Crack!!"
Very very cool stuff, and much much cleaner and functional than NUnit testing! Brilliant!