Michael Stephenson

keeping your feet on premise while your heads in the cloud
posts - 257, comments - 277, trackbacks - 11

My Links

News

View Michael Stephenson's profile on BizTalk Blog Doc View Michael Stephenson's profile on LinkedIn

Twitter












Archives

Post Categories

Image Galleries

BizTalk

Mates

Testing Schema with BizUnit

BizUnit is a unit testing framework for BizTalk.  This post will demonstrate how to test any schema you create using BizUnit to help you do this.

Problem

So the problem is that you have a schema which may change over time and you want to ensure it will always validate messages as you expect.  In BizTalk you have a context menu which allows you to validate this schema and also validate instances of messages against the schema.  The problem however is you want to do this as part of your unit tests so you want to automate this.

Solution

There are a number of ways this could be solved for example writing some C# to validate the schema but the new BizUnit framework allows us to simplify this task.  The following example demonstrates using BizUnit to test a schema.

1.  Solution Structure

In the following diagram you can see the solution structure being used in this diagram:

The key points to note are:

  • There is a project called Acme.Integration.Sample.Schemas which contains a simple schema for a customer details request message.
  • There is a project called Acme.Integration.Sample.Schemas.Tests which contains the stuff for testing the schemas project.

2. Acme.Integration.Sample.Schemas

This is a simple project containing 1 simple schema.

3. Acme.Integration.Sample.Schemas.Tests

This project contains 2 folders which are used to hold the test case and test data files used by BizUnit.  There is also a C# class which calls BizUnit to execute each test.  The following diagram shows some example tests used on this schema.  As you can see the tests are just like normal VSTS or NUnit tests with the exception that they call BizUnit to have it execute some steps for that individual test.

The test case executed by BizUnit are defined in an xml file.  The below diagram shows the file used for one of the tests against this schema.  As you can see we use the BizUnit FileExists step to validate the file we want to use (aka the test data file) is in the test directory (Note: I use the test run config file to copy all of the test cases and test data files to the testing directory).  Within the file exists step we also execute am XmlValidation step which points to our schema and runs the file against that

To create the test data file it is easiest to use the Generate Instance menu item on the schemas context menu to generate a valid document, and then edit this to suit your test case.

Note: This project should reference Microsoft.Services.BizTalkApplicationFramework.BizUnit

4. Running the Tests

The tests can be run just as normal VSTS & NUnit tests

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Sunday, September 17, 2006 11:42 AM | Filed Under [ BizTalk ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: