Monday, January 17, 2011

BizTalk Map test framework

For testing BizTalk solutions the combination of BizUnit and the orchestration profiler are the way to go. Setting it up for a new project can be a hassle, although i appreciate it’s flexibility with the easy of adding custom BizUnit steps.

I just came across a new framework that provides some usefull means of testing BizTalk artefacts, namely maps.

As you might have noticed the support for testing in BizTalk 2009 / BizTalk 2010 is somewhat limited and it forces you to build your artefacts with additional code for mere testing only (the check ‘Enable Unit Test’ will generate a wrapper around the components such as the TestableMapBase in the example below)….the most you will get out of the standard map testing is a validate instance of your message:

Microsoft.BizTalk.TestTools.Mapper.TestableMapBase mapTest = new MapTest.Input2Output();

mapTest.TestMap(
    @"Input.xml",   Microsoft.BizTalk.TestTools.Schema.InputInstanceType.Xml,
     "Output.xml",  Microsoft.BizTalk.TestTools.Schema.OutputInstanceType.XML);

This can be overcome by using a mapping helper component (e.g .from Michael Stephenson) that does a Binary or Xml validation of the result, nevertheless you don’t want to write this on your own.

MapTestingHelper.ValidateMapOutput("Output.xml", “Output.xml");

I’ve tried out the BizTalk map test framework and it allows you to write your testcases using Xpath on fields that you dynamically want to fill with dummy values and predicted outcomes.

Let’s say you want to test a value mapping that returns different results based on the input you can simply write a method that does this validation in just a few lines:

MapTestCases collection = new MapTestCases(
"/*[local-name()='Input']/*[local-name()='InputValue']",
"/*[local-name()='Output']/*[local-name()='ValueOut']"               );

            collection.AddTestCase(
                new string[] { "TEST" }, new string[] { "TRUE" }
                );

            collection.AddTestCase(
                new string[] { "AAH" }, new string[] { "FAL3SE" }
                );

            base.ExecuteMapTest(collection);
            return;

 

I think i like it….check it out here: BizTalk map test framework

No comments: