Search Wiki:
One of the greatest challenges of writing good tests is to keep the tests short and readable. This can be achieved by composition - here is the way I use to structure AAA-style tests using a few base classes:

 
[Test]
public void ProductValidator_IllegalProductCode_Fails()
{
    // Arrange
    var context = new TestContextBuilder<ProductValidatorContext>()
        .WithScenario(AnonymousProduct)
        .WithScenario(ProductHasIllegalProductCode)
        .BuildContext();
    
    ProductValidator sut = context.CreateSubjectUnderTest();
 
    // Act
    bool res = sut.Validate();
 
    // Assert
    Assert.IsFalse(res);
} 

The goal is to provide more readable tests and to encapsulate (and reuse) test setup code. This code gallery project contains the base classes for composing tests using this technique. Please read the related blog post for more information.
Last edited May 12 2010 at 10:56 AM  by peter_r, version 4
Updating...
Page view tracker