Creating a Coded BizUnit Test…

So how do I used 4.0 to create and execute a test? The code below shows how to create a simple coded test case:

[TestMethod]
public void DelaySampleTest()
{
    // Create the test case
    var testCase = new TestCase();

    // Create test steps...
    var delayStep = new DelayStep {DelayMilliSeconds = 500};

    // Add test steps to the required test stage
    testCase.ExecutionSteps.Add(delayStep);

    // Create a new instance of BizUnit and run the test
    var bizUnit = new BizUnit(testCase);
    bizUnit.RunTest();
}

The test case can then be saved to XAML – if you need to:

// Save Test Case
TestCase.SaveToFile(testCase, "DelaySampleTest.xml");

The XAML looks like this:

<TestCase Category=”{x:Null}” 
          Description="{x:Null}" 
          ExpectedResults="{x:Null}" 
          Name="{x:Null}" Preconditions="{x:Null}" 
          Purpose="{x:Null}" Reference="{x:Null}" 
          BizUnitVersion="4.0.133.0" 
          xmlns="clr-namespace:BizUnit.Xaml;assembly=BizUnit" 
          xmlns:btt="clr-namespace:BizUnit.TestSteps.Time;assembly=BizUnit.TestSteps" 
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <TestCase.ExecutionSteps>
    <btt:DelayStep 
          SubSteps="{x:Null}" 
          DelayMilliSeconds="500" 
          FailOnError="True" 
          RunConcurrently="False" />
  </TestCase.ExecutionSteps>
</TestCase>

The test XAML test case can be loaded and the BizUnit test executed as follows:

// Execute test csse using serialised test case to test round tripping of serialisation...
var bizUnit = new BizUnit(TestCase.LoadFromFile("DelaySampleTest.xml"));
bizUnit.RunTest();

When looking at the XAML you’ll notice that the test case has a bunch of null meta-data fields. These fields may be used to describe the tests. This meta data may be used to auto-generate documentation for the tests, I will add the code to do this at a future point.

Advertisements

~ by kevinsmi on March 23, 2011.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: