The Value of Writing Unit Tests
Do unit tests make sense from a business perspective? Jean-Paul S. Boodhoo's take here. BTW, if you're doing Agile development and don't read CodeBetter, now is a great time to start.
Randomly cohesive thoughts and ramblings...
Do unit tests make sense from a business perspective? Jean-Paul S. Boodhoo's take here. BTW, if you're doing Agile development and don't read CodeBetter, now is a great time to start.
Posted at 9:24 AM 0 comments
Here's a link to the slides and sample code I used for my talk at Code Camp. And here's a link to more information about Selenium: http://www.openqa.org/selenium/
Thanks for attending!
Posted at 11:39 AM 2 comments
When you start to write a substantial number of unit tests, you may discover that your tests have quite a bit in common. For instance, if you have a CreditCard class, you may have a block of code like this in each of your tests:
Assert.AreEqual( expectedCard.Number, actualCard.Number );
Assert.AreEqual( expectedCard.FirstName, actualCard.FirstName );
Assert.AreEqual( expectedCard.MiddleName, actualCard.MiddleName );
Assert.AreEqual( expectedCard.LastName, actualCard.LastName );
Assert.AreEqual( expectedCard.ExpMonth, actualCard.ExpMonth );
Assert.AreEqual( expectedCard.ExpYear, actualCard.ExpYear );
Assert.AreEqual( expectedCard, actualCard );
public class CreditCardUtil
{
public static void AssertAreEqual( CreditCard expected, CreditCard actual )
{
Assert.AreEqual( expected.Number, actual.Number );
Assert.AreEqual( expected.FirstName, actual.FirstName );
Assert.AreEqual( expected.MiddleName, actual.MiddleName );
Assert.AreEqual( expected.LastName, actual.LastName );
Assert.AreEqual( expected.ExpMonth, actual.ExpMonth );
Assert.AreEqual( expected.ExpYear, actual.ExpYear );
}
}
Posted at 11:30 PM 0 comments
Labels: unittesting programming
Oren Eini (aka Ayende Rahien) just released the latest version of Rhino Mocks, v3.0.5. This release includes a great new syntax for record and replay that will make your tests much easier to follow. Check out the syntactic sweetness here, be impressed, then download it here.
Posted at 10:40 PM 0 comments
When writing unit tests, I frequently find myself wanting to test private methods. I used to think there were only three approaches to solving this problem.
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
public class TestReflector
{
public static T InvokeNonPublicMethod<T>( string methodName, object obj,
params object[] parameters )
{
MethodInfo methodInfo =
obj.GetType().GetMethod( methodName, BindingFlags.NonPublic |
BindingFlags.Instance |
BindingFlags.Static);
if ( methodInfo == null )
{
throw new ApplicationException( "Private method not found for: '" +
methodName + "'." );
}
return (T)methodInfo.Invoke( obj, parameters );
}
}
MyClass myClass = new MyClass();
string string1 = "abcdef";
string string2 = "123456";
string result = TestReflector.InvokeNonPublicMethod<string>(
"MyPrivateMethod", myClass, string1, string2 );
Posted at 10:47 AM 5 comments
Thanks to everyone who attended my mock objects talk at Innotech today, I hope it wasn't too obvious that it was the first time I've presented at a conference ;-) As promised, I've posted my slides and source code here. Sorry about the ads, but Blogger doesn't support file uploads and this site was the best I could find on short notice. If you're here for the links, here you go:
Posted at 1:50 PM 4 comments
Labels: mock objects unit testing code development software c# agile