Michael Stephenson

Microsoft BPM/SOA Adventures
posts - 187, comments - 182, trackbacks - 15

My Links

News

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

Archives

Post Categories

Image Galleries

BizTalk

Mates

BizTalk Testing Series - Testing Schema

Overview
In my series of posts about how to improve the quality of BizTalk solutions you deliver I will begin by discussing how we normally test schemas on BizTalk projects I've worked on.
 
Most people seem to simply use the validate instance function within Visual Studio as the main way to test a schema. And although this can do the job I believe the approach has the following limitations:
 
1.       There is a known issue when validate instance sometimes thinks a message is valid when it isnt, see the following post by Yossi
 
2.       When you test the schema from the "Validate Instance" menu option in Visual Studio this needs to be done manually and is therefore not easy to automate
 
My preferred approach to testing schema is to write some tests in C# and use MsTest or Nunit to run them. The tests will typically load the sample input document and then use a helper class which will run the input document against the schema to confirm if it is valid or not.
 
The following picture from the sample accompanying this post shows how straight forward the code for the tests are:
 
 
 
Aim of Schema Testing
The aim of our testing approach relating to schemas is as follows:
 
·         We want to effectively and efficiently validate that our schema is correct against a set of sample messages
·         We want to ensure that any key validation logic in the schema can be tested
·         We want our tests to be automated and repeatable
·         We want the tests to validate any assumptions
·         We want to catch any problems as early as possible
·         We want our tests to be able to be ran as part of a continuous integration process
 
What kind of things do we test?
In our testing of schemas we want to be pragmatic. We could provide cases which would validate the schema in every possible way but when you have a large schema this may be time consuming. By being pragmatic we aim to balance the risk of not testing every possible case versus the expense of creating and maintaining the tests. An example of this is as follows:
 
If a developer has developed a schema with 10 elements under the root node. If 8 of these elements can have 0 - 3 occurrences then from one perspective we could say that the developer could need to do a whole set of tests covering what happens when each of the elements has 0, 3 and >3 occurences.
 
This example could quickly mount up to a lot of tests which would be a pain to maintain and change when required.
 
For this reason we would not really test these scenarios in most cases. The types of things we would be more likely to test are:
 
·         A known good sample message (The normal message we expect to receive) that it will validate
·         Any bad message cases which have been identified in the requirements and design stages
·         Things like regular expressions defined for a schema element
 
The Sample
In the sample (available below) I have a very simple schema within a BizTalk project. I also have a test project which contains some sample messages and a class which wraps up the logic to validate a message against its schema. 
 
If you want to follow our approach then take a look at the XmlValidation class as this is where the XmlValidatingReader is used to validate the input message against the schema.
 
Hopefully that is enough information on our approach to testing schemas within BizTalk development.
 

Print | posted on Sunday, March 30, 2008 12:13 AM | Filed Under [ BizTalk BizTalk Testing ]

Feedback

Gravatar

# re: BizTalk Testing Series - Testing Schema

The link to the sample download doesn't seem to work.....?
4/14/2008 1:40 PM | Mike
Gravatar

# re: BizTalk Testing Series - Testing Schema

Do you have any advice on how to test Flat File Schemas?
9/12/2008 10:23 AM | Anonymous
Gravatar

# re: BizTalk Testing Series - Testing Schema

There are really two considerations you want to make here

If you want the test the schema in isolation then usually with flat file schemas I will have some sample flat file messages and then use the Pipeline Component Test Library to run the message through the Flat File Disassembler. I will have a known template of the xml output that I would expect from the FFDasm component. I would then run a test to execute this and check that if I put in a certain message I get out exactly what I expect. You can also do this in reverse to check that a given XML message produces a specific flat file message. If you want help creating test instances of the xml and flat file messages I did a tool ages ago on codeplex which might help you (http://www.codeplex.com/BizTalkSampleMessage)

The second way you can do this is to test it aas part of your process which you test with BizUnit. You can run your messages through and check what comes out is as expected.

I will always do the BizUnit stuff anyway, but if there is some cases where I want to test parts of the schema validation etc i might do some tests in isolation if the bizunit tests are quite complicated. The key thing is to have a template of the message you expect out then do a binary comparison of the message which comes out and what you expect

I think i might do a post on this if it helps

Mike
9/12/2008 10:53 AM | Mike
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: