Export (0) Print
Expand All
3 out of 4 rated this helpful - Rate this topic

Defining Tests Using an XML Configuration File

BizUnit offers two ways to define tests: via an XML configuration file and via an Excel Spreadsheet. This topic focuses on using an XML configuration file to define tests, however, we also encourage you to look at the BizUnit SDK as it provides an interesting example of how to define BizUnit test cases using Excel. You may also wish to investigate the BizUnit Designer tool, which provides a GUI that allows for rapid creation of BizUnit test cases. This topic provides an overview of how to define test cases using XML configuration using a very simplified scenario. If you are already familiar with BizUnit, you may want to skip this topic and proceed to the detailed end-to-end scenario described in Using BizUnit with the Business Process Management Scenario.

As stated above, this scenario is simplified for purposes of illustration. Consider a sample messaging application such as the one illustrated below. Let’s assume that normal functional behavior for this application is that BizTalk receives an XML file via a file receive location, it then sends it to an appropriate subscriber based on a subscription. To validate this scenario effectively it is important that we perform the following steps in the test:

  1. Setup the environment to ensure that it is in a consistent state and ready for the test to be run:

    • This is done by deleting any files that are present in the two file locations used.

  2. Execute the test to verify functionality:

    • Create a valid XML message in the folder that the file receive location polls.

    • Validate that the correct XML message is placed in the outbound folder location.

    • The validation should cover both the schema and the payload information for the message (typically a couple of the key fields should be examined).

  3. Cleanup the environment to ensure that the environment is in the same state as before the test executed:

    • Delete any files that are present in the two file locations used.

Sample BizTalk Messaging Application

Each test case begins and ends with the TestCase XML tag, the testName parameter is passed into this as indicated below:

<TestCase testName="Test_01_FILECopyWithXmlValidation">

Then we enter the TestSetup phase, in which we ensure that the environment is in a consistent state to run the test. In this example, we delete any XML messages that are contained in our TestData directory. This is done using the FileDeleteMultipleStep:

   <TestSetup>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileDeleteMultipleStep">
         <Directory>..\..\..\TestData\</Directory>
            <SearchPattern>*.xml</SearchPattern> 
         </TestStep>
   </TestSetup>

We then enter what is the most critical section of the test, the test execution stage. This stage can contain multiple test steps. In this example we use the FileCreateStep to cope a document (InDoc1.xml which can be seen in the <SourcePath> tag) to a file drop which is used by out receive location. It’s important to note that BizUnit supports using unique identifiers for filenames in this step, this can be seen with the %Guid% reference in the CreationPath tag.

After this has been completed, we need to use the FileValidateStep to validate the outbound message has been created. You will notice this step allows you to specify a timeout value (this is in milliseconds), the directory and the search pattern. In addition to this, the DeleteFile tag enables you to specify whether you want the file to be removed after it has been validated. Finally, you should also note the validation includes an XPath query, which validates the PONumber node within the XML message (it checks that the value is PONumber_0.) Examination and validation of the payload of any outbound messages is another example of a guiding principle that you should follow when using BizUnit.

   <TestExecution>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep">
         <SourcePath>..\..\..\TestData\InDoc1.xml</SourcePath>
         <CreationPath>..\..\..\Rec_03\TransactionId_%Guid%.xml</CreationPath>
      </TestStep>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileValidateStep">
         <Timeout>3000</Timeout>
         <Directory>..\..\..\Rec_03\</Directory>
         <SearchPattern>TransactionId_*.xml</SearchPattern>
         <DeleteFile>true</DeleteFile>
         <ValidationStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep">
            <XmlSchemaPath>..\..\..\TestData\PurchaseOrder.xsd</XmlSchemaPath>
            <XmlSchemaNameSpace>http://SendMail.PurchaseOrder</XmlSchemaNameSpace>
            <XPathList>
               <XPathValidation query="/*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']">PONumber_0</XPathValidation>
            </XPathList>
         </ValidationStep>
      </TestStep>
   </TestExecution>

The final stage of the test case is the cleanup. As can be seen below, the FileDelete test step is used to clean up the directories used by the test.

   <TestCleanup>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileDeleteMultipleStep">
         <Directory>..\..\..\TestData\</Directory>
         <SearchPattern>*.xml</SearchPattern> 
      </TestStep>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileDeleteMultipleStep">
         <Directory>..\..\..\Rec_03\</Directory>
         <SearchPattern>*.xml</SearchPattern> 
      </TestStep>
   </TestCleanup>

Hopefully this example illustrates that defining tests in BizUnit is relatively straightforward and that by using this test framework, you will be able to rapidly develop test cases to provide functional testing of your application.

Full test case example

The full test case configuration file contents are included below for your reference:

<TestCase testName="Test_01_FILECopyWithXmlValidation">
   <TestSetup>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileDeleteMultipleStep">
         <Directory>..\..\..\TestData\</Directory>
            <SearchPattern>*.xml</SearchPattern> 
         </TestStep>
   </TestSetup>
   <TestExecution>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep">
         <SourcePath>..\..\..\TestData\InDoc1.xml</SourcePath>
         <CreationPath>..\..\..\Rec_03\TransactionId_%Guid%.xml</CreationPath>
      </TestStep>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileValidateStep">
         <Timeout>3000</Timeout>
         <Directory>..\..\..\Rec_03\</Directory>
         <SearchPattern>TransactionId_*.xml</SearchPattern>
         <DeleteFile>true</DeleteFile>
         <ValidationStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep">
            <XmlSchemaPath>..\..\..\TestData\PurchaseOrder.xsd</XmlSchemaPath>
            <XmlSchemaNameSpace>http://SendMail.PurchaseOrder</XmlSchemaNameSpace>
            <XPathList>
               <XPathValidation query="/*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']/*[local-name()='PONumber' and namespace-uri()='']">PONumber_0</XPathValidation>
            </XPathList>
         </ValidationStep>
      </TestStep>
   </TestExecution>
   <!-- Test cleanup: test cases should always leave the system in the state they found it -->
   <TestCleanup>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileDeleteMultipleStep">
         <Directory>..\..\..\TestData\</Directory>
         <SearchPattern>*.xml</SearchPattern> 
      </TestStep>
      <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileDeleteMultipleStep">
         <Directory>..\..\..\Rec_03\</Directory>
         <SearchPattern>*.xml</SearchPattern> 
      </TestStep>
   </TestCleanup>
</TestCase>
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.