Importing BizUnit Test Cases…

Often test cases are built up progressively testing more and more functionality, or they are built in a manner whereby they have dependencies. The diagram below illustrates this, test case #6 is dependent on test case 3, which is in turn dependant on test case 1 and 2.


A real world example of this might be where a GetBookingStatus web service operation needs to be tested, GetBookingStatus takes a bookingId, so before it can be called, CreateBooking needs to be called which returns a bookingId. In order to test GetBookingStatus, a CreateBooking test can be created, which returns a bookingId and sets it in the BizUnit context, next GetBookingStatus is called, but the request message is modified using an Xml data loader setting the bookingId of the request message to the value previously set in the context. This example shows how the various BizUnit features maybe used to achieve a reasonably complex scenario.

To achieve this, BizUnit offers the ability to import a test case at any stage within another test case. The code below illustrates a simple import scenario. The first test case creates a file “File1.xml”. The second test case imports the first test case, then creates a second file “File2.xml”, then uses a validating file read step to check that two files were created that also validate against the defined schema. The code below illustrates this.

Using BizUnit.TestSteps.Common;
using BizUnit.TestSteps.DataLoaders.File;
using BizUnit.TestSteps.File;
using BizUnit.TestSteps.ValidationSteps.Xml;
using BizUnit.Xaml;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BizUnit.TestSteps.Tests.ImportTestCase
    public class ImportTestCaseTest
        public void ImportSingleTestCaseTest()
            // Create the first test case i a helper method...
            var testCase1 = BuildFirstTestCase();

            // Create the second test case and import the first test case into it...
            var testCase2 = new TestCase {Name = "Copy First File Test"};

            var createFileStep = new CreateStep {CreationPath = @"File2.xml"};
            var dl = new FileDataLoader
                             FilePath = 
            createFileStep.DataSource = dl;


            var import = new ImportTestCaseStep {TestCase = testCase1};
            // Create a validating read step...
            var validatingFileReadStep = new FileReadMultipleStep
                                   DirectoryPath = @".",
                                   SearchPattern = "File*.xml",
                                   ExpectedNumberOfFiles = 2

            var validation = new XmlValidationStep();
            var schemaPurchaseOrder = new SchemaDefinition
                XmlSchemaPath =
                XmlSchemaNameSpace =

            var xpathProductId = new XPathDefinition
                                         Description = "PONumber",
                                         XPath =
                                             "/*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']",
                                         Value = "12323"

            // Run the second test case...
            var bizUnit = new BizUnit(testCase2);

        private TestCase BuildFirstTestCase()
            var testCase1 = new TestCase {Name = "Copy First File Test"};

            var step = new CreateStep();
            step.CreationPath = @"File1.xml";
            var dl = new FileDataLoader();
            dl.FilePath = 
            step.DataSource = dl;
            step.Execute(new Context());

            return testCase1;

The same coded test case shown above may also be defined in XAML as shown below:

<TestCase Category="{x:Null}" Description="{x:Null}" ExpectedResults="{x:Null}" Preconditions="{x:Null}" Purpose="{x:Null}" Reference="{x:Null}" BizUnitVersion="" Name="Copy First File Test" 
  xmlns:x="" >
    <btf:CreateStep SubSteps="{x:Null}" CreationPath="File2.xml" FailOnError="True" 
          FilePath="..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.xml" />
    <ImportTestCaseStep SubSteps="{x:Null}" TestCasePath="{x:Null}" FailOnError="True" 
        <TestCase Category="{x:Null}" Description="{x:Null}" ExpectedResults="{x:Null}" 
          Preconditions="{x:Null}" Purpose="{x:Null}" Reference="{x:Null}" 
          BizUnitVersion="" Name="Copy First File Test">
            <btf:CreateStep SubSteps="{x:Null}" CreationPath="File1.xml" FailOnError="True" 
                    "..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder001.xml" />
    <btf:FileReadMultipleStep DeleteFiles="False" DirectoryPath="." ExpectedNumberOfFiles="2" 
      FailOnError="True" RunConcurrently="False" SearchPattern="File*.xml" Timeout="0">
            <btc:XPathDefinition ContextKey="{x:Null}" Description="PONumber" Value="12323" 
              XPath="/*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']" />
            <btvx:SchemaDefinition XmlSchemaNameSpace="http://SendMail.PurchaseOrder" 
              XmlSchemaPath="..\..\..\Test\BizUnit.TestSteps.Tests\TestData\PurchaseOrder.xsd" />
The depth of the import functionality is arbitrary, providing the test cases scenarios are designed in a logical and sensible manner leveraging import can give big productivity gains when developing tests.

~ by kevinsmi on March 23, 2011.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: