Search Wiki:

BizUnit

The adoption of an automated testing strategy is fundamental in reducing the risk associated with software development projects, it is key to ensuring that you deliver high quality software. Often, the overhead associated with developing automated tests is seen as excessive and a reason to not adopt automated testing.

BizUnit enables automated tests to be rapidly developed. BizUnit is a flexible and extensible declarative test framework targeted that rapidly enables the automated testing of distributed systems, for example it is widely used to test BizTalk solutions. BizUnit is fully extensible. Its approach is to enable test cases to be constructed from generic reusable test steps, test cases are defined in XML which allows them to be auto-generated and also enables the ‘fixing up’ of Url’s for different environments, e.g. test, staging and production environments. Defining test cases in XML enables test cases to be auto-generated.


BizUnit v3.0 - Beta 2 - now available, new features include a BizUnit object, Excel test case runner and a new UI automation test step library

BizUnit is a framework and as such does not have any dependency on either NUnit of VS Unit Testing, either of these make a great way to drive BizUnit test cases, though equally you could write custom code to do the same.

Test Case Format

A test case can be represented as an Xml document or using the BizUnit object model, it is made up of three stages, test setup, test execution and test cleanup, the cleanup stage is always executed (even if the main execution stage fails) and intended to leave the platform in the same state that it started.
Each stage may consist of zero or more test steps, test steps are in general autonomous, state can be flowed between them if required using the ‘context’ object that is passed to each test step by the framework.
BizUnit also has the notion of TestGroupSetup and TestGroupTearDown, these are test cases that are executed at the beginning and end of a suite of unit tests.

The diagram below illustrates the format of a test case.

TestCase.jpg

In addition to test steps, BizUnit has the notion of validation steps and context loader steps. These can be thought of as sub-steps and can in general be independantly executed from any test step. For example, an MSMQ-read step might be used to read and validate both Xml and Flat File data from a queue, the same step can be used with both the RegExValidationStep and the XmlValidationStep to validate the data read.

A test step within a test case can be marked with the attribute - runConcurrently which causes subsequent test steps to be started before it has completed. In addition test steps maybe marked with the attribute - failOnError, setting it to false cause BizUnit to ignore a failure of that test step, this is particularly useful for the setup and cleanup stages of test cases.

Lets look at an Example Scenario...

BizUnit takes a black box approach to testing solutions, lets look at the BizTalk scenario below, a BizTalk solution receives a request-response message over HTTP, the message is routed to an Orchestration which, sends a message to MSMQ and another to a FILE drop, the Orchestration waits for a FILE to be received, after which the Orchestration sends the response back to the waiting HTTP client. The solution also uses BAM, writing business data to the BAM database.

BizUnitExample.jpg

In order to test this scenario, a BizUnit test case is defined that has 5 test steps:

  • The HttpRequestResponseStep sends the request to the two-way receive port and waits for the response. This step is executed concurrently so that the other test steps may execute whilst it waiting for the response
  • The MSMQReadStep waits for a message to appear on an MSMQ queue.
    • When it reads the message it uses the XmlValidationStep to perform schema validation and also execute a number of XPath expression to ensure the message contains the correct data
  • The FileValidateStep waits for a FILE to be written to a given directory
    • When it reads the FILE it validates the data using the RegExValidationStep validation step since the FILE picked up was a flat file format
  • The FileCreateStep creates a new FILE in the specified directory containing the data that the backend system would typically create. This allows the Orchestration to complete and send the response back to the waiting HttpRequestResponseStep step
  • Finally, DBQueryStep is used to check that all of the BAM data has been successfully written to the BAMPrimaryImportDB

Test Steps

A test step is a .NET class which implements the ITestStep interface:

public interface ITestStep
{
    void Execute(XmlNode testConfig, Context context);
}

BizUnit will create and execute the test steps as dictated by the Xml test case. The test case will list the steps that need to be excuted in each stage of the test. The example below will cause BizUnit to create the Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep. BizUnit uses the assemblyPath and typeName to load and create the type:

<TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep">
    ...
</TestStep>

Executing Steps Concurrently

Test steps can be maked to execute concurrently by decorating them with the runConcurrently attribute:
<TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.HttpRequestResponseStep" runConcurrently="true">
    ...
</TestStep>

Reading Configuration from Context

BizUnit enables state to be flowed between test steps using the Context object, subsequent steps may read configuration from the Context object which was written by a previous test step, this is acheived using the takeFromCtx attribute within a steps configuration. For example:

<TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.HttpPostStep">
    <SourcePath>.\TestData\InDoc1.xml</SourcePath>    
    <DestinationUrl takeFromCtx="HTTPDest">http://localhost/TestFrameworkDemo/BTSHTTPReceive.dll</DestinationUrl>
    <RequestTimeout>60000</RequestTimeout>
</TestStep>

Wild Cards

BizUnit supports wild card for reading configuration, the following wild cards are supported

  • %DateTime% - will replace the wild card with the current date time in the format HHmmss-ddMMyyyy
  • %ServerName% - will replace the wild card with the name of the server BizUnit is being executed on
  • %Guid% - will be replaced by a new Guid

For example, for the test step configuration below:

<TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileCreateStep">
    <SourcePath>..\..\..\TestData\InDoc1.xml</SourcePath>         
    <CreationPath>..\..\..\Rec_03\TransactionId_%Guid%_%ServerName%.xml</CreationPath>
</TestStep>

CreationPath becomes "..\..\..\Rec03\TransactionId12345678-D6AB-4aa9-A772-938972E3FD51ZEUS001.xml"_

Validation Steps

BizUnit supports the notion of validation steps which may be nested within test steps which support validation. This means that an MSMQ read step may use an XML validation step or a regular expression validation step to validate the data that it receives. Validation steps need to implement the IValidationStep interface.

public interface IValidationStep
{
    void ExecuteValidation(Stream data, XmlNode validatorConfig, Context context);
}

A test step may use the Context object utilities to execute the appropriate validation step as shown below:

public void Execute(XmlNode testConfig, Context context)
{
    XmlNode validationConfig = testConfig.SelectSingleNode("ValidationStep");
    MemoryStream data = null;
 
    ...
 
    context.ExecuteValidator( data, validationConfig );
}

The test step snippet below illustrates how a validation step is embeded in a file read step:

<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>

Context Loader Steps

Similarly, BizUnit supports context loader steps, which are responsible for loading data into the BizUnit context. These types of need to implement the IContextLoaderStep interface as shown below:

public interface IContextLoaderStep
{
    void ExecuteContextLoader(Stream data, XmlNode contextConfig, Context context);
}

Getting Started

The best way to get started is to download the latest version, install it and then take a look at the SDK samples. All the source is currently included, so feel free to take a closer look at the code. All the test steps along with the framework itself are documented in the .CHM that is installed.

Finally, my apologies for the shameless plug :-), but Chapter 10 of Professional BizTalk Server 2006 book which I co-authored discusses in more detail how BizUnit may be used as an integral part of your development process, and how it may be used to drive stress and performance testing.

BizTalk2006Book.jpg

Acknowledgments

I'd like to thanks the follwing people who have contributed to BizUnit in some way, either by donating test steps, identifying bugs, or by providing requirements which have subsequently been implemented. I may have missed some people off, if so, it's not intensional, please drop me a mail to remind me:

Dharshana Kalahejagoda
Jon Fancey
Isaac Young
Mike Becker
Tanveer Rashid
Young Jun Hong
Dave Regan
Ian Cross
Greg Beach
Daren Jefford
Kevin Purcell
Karina Apostolides
Jon Bonnick
Brian Milburn
Rahmatullah Khan

Enjoy!
Last edited May 8 at 8:09 AM  by kevinsmi, version 26
Comments
santoshbenjamin wrote  Mar 9 2007 at 11:59 PM  
Hi Kevin, good to see this project here. There are two of us running the BizUnitExtensions project here on CodePlex where we have added a lot more steps and fixed lots of bugs in the code base. Are you going to be actively contributing to BizUnit here? we have lots of plans to extend the BizUnitExtensions project and thats all explained in the roadmap. Maybe we could join forces? what do you think?

kevinsmi wrote  Apr 10 2007 at 9:37 PM  
Hi,
The new release of BizUnit will be coming soon, it incorporates a bunch of things which were the result of (a) the last performance tuning session that I ran in the BizTalk Server Product group labs over in Redmond and (b) some other things related to some heavy usage in non-BizTalk related scenarios.

Great to see your BizUnitExtensions project up here. In terms of working together, yes absolutely, as mentioned, the approach to BizUnit is that I am the librarian, and as such I police and integrate the work from the many people who have contributed steps, bug fixes and ideas to BizUnit (hopefully the have all been given credit above). Some 50 to 70% of the steps in the current version were developed by contributors in this way, the model has worked very well to date. I would be very happy to include any test step libraries that you have in addition to those in the current version, for example your Oracle library looks useful. Likewise for any bug fixes, I’ve diff’d your changes with the current version and will try to incorporate any bug fixes that are relevant.

A couple of other points around your project which I’d encourage you to think about, I fully support you guys working on new test steps that add value to BizUnit and ultimately help more people to take an automated test approach to BizUnit. I set up this community project initially because I was very concerned around the lack of testing that BizTalk projects were getting, anything that we can do to lower the bar for automated testing further is definitely goodness. That said, I don’t support the redistribution of a branched version of the BizUnit framework and existing test steps. BizUnit has some 6000+ downloads to date, branching the framework is not something that I either encourage or support. The source code is provided should you hit a bug that you need to fix urgently, and not so that it can be branched and redistributed. The framework and test steps are very simple making it easy to fix such bugs. I’m sure you understand the issues associated with redistribution of the framework, for example, your branched version of the framework is now quite significantly out of date and contains a number of bugs that have been fixed in main.
Thanks and regards,
Kevin

santoshbenjamin wrote  Apr 17 2007 at 9:56 PM  
Hi , Thanks for getting back. I'll have a chat with my co-contributor on Extensions and we'll work out how we can merge back with you. I certainly dont want any clashes with the core code base. Do let me know your comments on the roadmap too.

Regards,
benjy

kevinsmi wrote  Apr 21 2007 at 8:45 PM  
Hi Benjy,

Sounds good. I suggest the way forward would be to:
(a) see if you have fixed any bugs in main that I have not fixed in the current release which is imminent, I've diff'd the code base and there were a couple of things which I believe I now have covered off. There were some changes to main that I didn't agree with and I have rejected those changes, we can discuss those and the reasons why if you have questions.
(b) I suggest that you package any test steps that are new into TestStepLibraries, I'd see these as standalone, you guys should continue to innovate and move those forward as you see fit and users can download them from the Extensions project as required. From memory, the Oracle steps would make a logical TestStepLibrary. The general principal is that a new library is created to partition any dependencies, for example the LoadGen library, users should not have to install LoadGen simply to compile main. I’ll get a beta drop of the new version out so you guys can diff it.

Regarding the roadmap, I’ve had a look, there are some good ideas, some things that have already been done, some things that are less interesting from my personal perspective and some vague ideas also - could well be things that could be cultivated into something more compelling. My advice to you guys would be to pick something, focus on it and do it well.

Some of the big ticket items have already been done (the sign of a good idea is when someone else builds it first :-)), developed by various companies and consultancies that I have worked with whilst at Microsoft. For example, more than a year ago one of my customers who took a heavy dependency on BizUnit developed a graphical user interface which was integrated into Visual Studio in order to design and author BizUnit test cases. The project was successful. I am aware of another such effort, as is often the case with such ventures companies are often not keen to release those tools into the open due to the investment that they have made and any competitive edge they feel it gives them. In my view is perfectly reasonable. The test case authoring tool is something that I have personally been planning to pull together for a long time, but just not had time, in my view that would be a great extension to BizUnit and really help to broaden its appeal.

Quite a few of the companies that I have worked with get around this using spread sheets to define test matrixes and ultimately generate the Xml from those spread sheets. This approach generally seems to work well.


Integration with WF has also been done by a consultancy that I have had close involvement with for a number of years, again they have invested significantly in that effort and from what I’ve seen of it, it looks like a great testing tool. Again, this would be useful, but to do it well is actually quite a lot of work.

Some more thoughts on different topics:

WCF Test Step Library: absolutely this would be very useful.

EntLib logging: all steps should use the BizUnit ctx object to perform logging, any shortfalls in logging should be addressed in the steps to log out enough information during their execution, the sink used whether its stdout or entlib with not help, fundamentally it’s the steps that need to raise sufficient logging. The BizUnit logger maybe swapped out to use a different logger, I actually always intended to expose this so other types of logger could be injected but never got around to it. Some companies have swapped in there own loggers to dump the output to HTML for example. I agree there is value in enabling this more easily, but switch to EntLib is not interesting to me personally since the test output should be aggregated by the test driver, e.g. VS Unit Testing.

Integration Testing Framework: BizUnit has never been restricted to BizTalk testing, indeed when I first built it I was thinking much wider than BizTalk, but the BizTalk community at that time was in desperate need to such a framework. I know of many companies that use it for non-BizTalk testing, including the bank that I now work for as it happens. In early versions you needed some BizTalk binaries to compile the solution, but that has not been the case for a while now. Changing the name does not help, I'm currently using it for testing a high perf trading system, nothing to do with integration, so ITF as a name is no more approapriate to BizUnit.

I hope that helps, as I say, my advice for you chaps would be to focus on a feature and deliver something that adds value to a broad audience.

Thanks,

Kevin

santoshbenjamin wrote  Apr 25 2007 at 6:18 PM  
Cheers Kevin!!! wow, thats a lot to chew on..
should we move the discussions here to the discussion forum area? i'll set the ball rolling by putting in my responses to these points there.
Thanks
Benjy

praneethreddy wrote  Mar 23 at 3:10 AM  
Hi Kevin,

Firstly, great work on the project, it has saved me a lot of effort in testing my applications. However, I find creating the xml test cases tedious. So, I created BizUnit Designer - a GUI that allows rapid creation of BizUnit test cases. The project is located at http://www.codeplex.com/bud. Let me know if you have any thoughts on improving the project.

Thanks,
Praneeth

Updating...