Skip to main content
Email Password   helpLost your password?

Introduction - Unit Testing

Essentially a Unit Test is a procedure, used to validate a particular piece of source code. Effective Unit Testing is vital to the success of any project. Unit Testing results in reduced defects in the next level of testing. Traditionally we have used NUnit to test any assembly (*.DLL). For testing BizTalk Orchestrations we use a similar approach. We test BizTalk Orchestrations as a Black Box.

Required Downloads

We would need to download the following, in order to perform unit testing of BizTalk Orchestrations.

Overview - Purchase Order Sample

Schemas

The screen shot below shows the Purchase Order (PO) schema and the Purchase Order Acknowledgement (POA) schema.

PO and POA schemas

Transformation Map - PO to POA

The screen shot below shows the transfomation of PO to POA.

Orchestration

The screen shot below shows the POProcess Orchestration.

ProcessPO Orchestration Summary

Sample PO data using InfoPath 2003

The screen shot below shows the sample Purchase Order (PO).

Using BizUnit2006 to perform Orchestration Unit Testing

After the installation of BizUnit2006, create a new "class library" project in Visual Studio 2005 and add the following code as shown below...

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Services.BizTalkApplicationFramework.BizUnit;
using NUnit.Framework;

namespace BizTalkUnitTest
{
    [TestFixture]
    public class TestPO
    {
        public TestPO()
        {
        }

        [TestFixtureSetUp]
        public void Setup()
        {
            // Stopping and Starting BizTalkHostInstance

            BizUnit bizUnit = new BizUnit(@"C:\PurchaseOrderSystem\TestCases\Test_Setup.xml", 
                BizUnit.TestGroupPhase.TestGroupSetup);
            bizUnit.RunTest();
        }

        [Test]
        public void ValidatePO_Rejected()
        {
            // Testing Orchestration - PO - Rejection

            BizUnit bizUnit = new BizUnit(@"C:\PurchaseOrderSystem\TestCases\Test_1_POSystem.xml");
            bizUnit.RunTest();
        }

        [Test]
        public void ValidatePO_Approved()
        {
            // Testing Orchestration - PO - Approval

            BizUnit bizUnit = new BizUnit(@"C:\PurchaseOrderSystem\TestCases\Test_2_POSystem.xml");
            bizUnit.RunTest();
        }
    }
}

Points to note in the above code

using Microsoft.Services.BizTalkApplicationFramework.BizUnit;
using NUnit.Framework;
BizUnit bizUnit = new BizUnit(@"C:\PurchaseOrderSystem\TestCases\Test_1_POSystem.xml");
bizUnit.RunTest();

The BizUnit Test Case XML File

The BizUnit XML file used to test the Orchestration is shown below

<TestCase testName="Test_1_ProcessPO">

<TestSetup>
</TestSetup>

<TestExecution>
    <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep">
        <SourcePath>C:\PurchaseOrderSystem\InputFiles\PO_001.xml</SourcePath>
        <CreationPath>C:\PurchaseOrderSystem\POIn\PO_001.xml</CreationPath>
    </TestStep>

    <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileValidateStep">
        <Timeout>60000</Timeout>
        <Directory>C:\PurchaseOrderSystem\POAckOut</Directory>
        <SearchPattern>*.xml</SearchPattern>
        <DeleteFile>true</DeleteFile>

        <ValidationStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep">
            <XmlSchemaPath>C:\PurchaseOrderSystem\POA.xsd</XmlSchemaPath>
            <XmlSchemaNameSpace>http://PurchaseOrderSystem.POA</XmlSchemaNameSpace>

            <XPathList>
                <XPathValidation query="/*[local-name()='POAck' and 
                namespace-uri()='http://PurchaseOrderSystem.POA']/*[local-name()='PONum' and 
                namespace-uri()='']">PO_001</XPathValidation>
                <XPathValidation query="/*[local-name()='POAck' and 
                namespace-uri()='http://PurchaseOrderSystem.POA']/*[local-name()='POItemsCount' and 
                namespace-uri()='']">2</XPathValidation>
            </XPathList>
        </ValidationStep>
    </TestStep>

    <TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileValidateStep">
        <Timeout>60000</Timeout>
        <Directory>C:\PurchaseOrderSystem\POOut</Directory>
        <SearchPattern>*.xml</SearchPattern>
        <DeleteFile>true</DeleteFile>

        <ValidationStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep">
            <XmlSchemaPath>C:\PurchaseOrderSystem\PO.xsd</XmlSchemaPath>
            <XmlSchemaNameSpace>http://PurchaseOrderSystem.PO</XmlSchemaNameSpace>

            <XPathList>
                <XPathValidation query="/*[local-name()='PORequest' and 
                namespace-uri()='http://PurchaseOrderSystem.PO']/*[local-name()='PONum' and 
                namespace-uri()='']">PO_001</XPathValidation>
                <XPathValidation query="/*[local-name()='PORequest' and 
                namespace-uri()='http://PurchaseOrderSystem.PO']/*[local-name()='POStatus' and 
                namespace-uri()='']">REJECTED</XPathValidation>
            </XPathList>
        </ValidationStep>
    </TestStep>

</TestExecution>

<!-- Test cleanup: test cases should always leave the system in the state they found it -->
<TestCleanup>

</TestCleanup>

</TestCase>

XML TestCase - Points to note

NUnit GUI

The screen shot below shows the NUnit GUI

Event Viewer

The screen shot below shows the Event Viewer, observe the events listed.

About the downloadable code

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralA new BizTalk unit testing framework you might be interested in ... Pin
Ali Kheyrollahi
2:19 9 Mar '09  
GeneralBizUnit testing with the "FactBasedRuleEngineStep" Pin
ONeil Tomlinson
3:10 30 Oct '08  
Questioncan you get a example on this orchestration by LoadGen? Pin
etehadi
0:49 3 Aug '08  
QuestionBizUnit using the "FileValidateStep" Pin
ONeil Tomlinson
0:24 25 Jun '08  
GeneralBizUnit Designer Pin
Member 2038319
4:26 23 Mar '08  
GeneralBinding Info Problem... Pin
rajatpk
9:49 29 Nov '07  
GeneralBizUnit Error! The path is not of legal form! Pin
Chenue
5:48 10 May '07  
GeneralRe: BizUnit Error! The path is not of legal form! Pin
Naveen Karamchetti
5:52 10 May '07  
GeneralRe: BizUnit Error! The path is not of legal form! Pin
Chenue
23:22 10 May '07  
GeneralBizUnit with SOAP Pin
BizTalkFreak
8:23 12 Mar '07  
GeneralBizUnit with SOAP Pin
BizTalkFreak
8:16 12 Mar '07  
GeneralRe: BizUnit with SOAP [modified] Pin
ofilipe
7:03 7 Feb '08  


Last Updated 26 Apr 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009