Home > Articles

This chapter is from the book

Testing of Maps

A map performs a transformation from one XML format into another. It is essential that the output generated is valid given the schema that describes the output, because otherwise you are sending invalid messages to trading partners and internal systems.

The Mapper helps you generate XSLT that generates valid XML, and it warns you about certain issues when validating the map or when compiling the project. Ultimately, however, it is the responsibility of the developer to make sure that the output generated by a map is valid.

This means that after developing your map you want to test it. Preferably, test all possible cases the map can get into at runtime. This section walks you through your options for testing your map.

Validating Maps

First of all, when developing a map, you should validate it. This is done by right-clicking the map file (.BTM) in Solution Explorer and choosing Validate Map. This will let Visual Studio 2010 go through the map and check for different kinds of syntactical errors such as functoids with the wrong number of inputs and other such things. If no errors occur, the map can be compiled and deployed.

The validation might be successful but with some warnings. If warnings occur, you must decide whether to ignore them because you know you have handled the issue the warning is about or whether you must do something about it. A warning that you will probably see many times is the “Warning btm1004: The destination node ‘NameOfNode’ has multiple inputs but none of its ancestors is connected to a looping functoid.” Basically, this warning comes because you have multiple source nodes connected to the same output node. This can be by design if you are using multiple Value Mapping functoids to do conditional mapping of values into one node.

Warnings are there for a reason, so take them seriously and deal with them all. As a general rule, BizTalk by default does not validate any messages sent out, meaning that your map really needs to be working well.

Testing Maps

After validating your map, you can test it from within Visual Studio 2010. To test the map, you need to provide Visual Studio 2010 with a test instance. You can set some properties on a map file (.BTM) in Solution Explorer to facilitate this. Figure 3.40 shows these, and they are explained in Table 3.15.

Figure 3.40

Figure 3.40. The properties you can set on a .BTM file in Solution Explorer.

Table 3.15. Properties on .BTM Files for Testing a Map



TestMap Input

Can be either Generate Instance, XML, or Native. If set to Generate Instance, Visual Studio 2010 generates an instance of the source schema for the map and uses that as test instance no matter what the other properties are set to. If set to XML, Visual Studio 2010 assumes that the instance you are providing for testing the map is in XML format. If set to Native, Visual Studio 2010 assumes that the instance you are providing is in the native format of the source schema. This allows you to use a flat file or EDI instance as a test instance. Visual Studio 2010 then first converts it into XML using the appropriate schema and editor extensions and uses the XML as input.

TestMap Input Instance

Full path to the file to use as test instance for the map. If the TestMap Input is set to Generate Instance, this property is ignored.

TestMap Output

Can be set to either XML or Native. Determines whether the output of testing the map should be in XML format or the format that is native for the destination schema in the map.

TestMap Output Instance

Full path to where Visual Studio 2010 should write the output of testing the map. If this is not specified, the output is written to a temporary file. The full path to the file that is generated is always written in the output window, giving you access to open it after the test is done.

Validate TestMap Input

If set to true, the instance that is either generated or read from a file is validated against the schema before the map is executed. If set to false, the map is executed without validation.

Validate TestMap Output

If set to true, the output of the map is validated against the schema for the output. If set to False, the output is not validated and written to a file as is.

After setting the properties as you want, you can test the map by right-clicking the .BTM file and choosing Test Map, as shown in Figure 3.41.

Figure 3.41

Figure 3.41. How to test your map.

After you choose the Test Map option, Visual Studio 2010 reads the properties on the .BTM file as specified in Table 3.15 and tests the map. If the test is successful, you get a link to the generated output in the output window. If the test fails, you receive a list of errors in the Error List window. A test is considered successful if no exceptions are thrown during execution and if input and output validation succeeds, if turned on. Exceptions can occur during execution if the Assert functoid is used or if a functoid actively throws an exception.

Debugging a Map

If your map does not provide you with the output you need and expect, some debugging might be in order. BizTalk supplies you with the option to debug your map line for line to see what happens.

Unfortunately, this functionality does not work for referenced functoids because the debugger cannot find the right external assemblies at runtime. If you want to debug your map and you are using functoids, it is therefore a good idea to make sure you are using the inline versions of all functoids, where possible. The functoids that are shipped with BizTalk, for instance, often have both an inline implementation and a referenced implementation. Which implementation to use when a functoid supports multiple implementations is controlled by the Script Type Precedence property of the Mapper grid. When you click the ellipsis for that property, you get a small window where you can set the script type precedence, as shown in Figure 3.42.

Figure 3.42

Figure 3.42. Setting the Script Type Precedence property.

Basically, you should get the External Assembly possibility moved to the bottom to make sure external assemblies are used as a last resort. If you trust that the inline versions of the functoids is equal to the version that is referenced, you can change the order back after debugging if you want to.

After setting the Script Type Precedence, you need to set the value of the TestMap Input Instance property to point to the instance you want to use as input when debugging the map. You can also specify the TestMap Output Instance if you would like to control the filename the output is written to.

After setting these properties, you can right-click your .BTM file in Solution Explorer and choose Debug Map. Visual Studio 2010 then generates the XSLT that is to be debugged and opens it with a breakpoint already set on the first line. Besides this pane, two other panes are also opened. The first contains the output, which lets you keep track of the output that is built while the map is being debugged, and the other is the input XML, which lets you see which fields in the input XML are currently used to build the output. You can drag the windows around so that you can see all three panes at the same time. Figure 3.43 illustrates this.

Figure 3.43

Figure 3.43. Debugging a map.

As you can see in Figure 3.43, three panes are open: the XSLT, the input XML, and the generated output. As you can also see at the bottom of the figure, you get the watches, as well, thus enabling you to keep track of the values of the variables and optionally change the values at debug time to test what will happen. Also, you can set breakpoints and use F5 (to run until next breakpoint), F10 (to step over the currently active line of code), and F11 (to step into the currently active line of code), as you are used to doing when debugging .NET code inside Visual Studio 2010.

Unit Testing

After a map is developed, validated, tested, and possibly debugged, you should enable unit testing of the map. As a matter of fact, many great people insist you should write your unit tests before even starting developing anything. This is called test-driven development (TDD). In either case, BizTalk ships with the option to do unit testing on your maps, which you should leverage, and this section describes this functionality.

The first thing to do is to enable unit testing on the project that contains a map you want to unit test. To do so, follow these steps:

  1. Go to Solution Explorer.
  2. Right-click the project that contains the map that is to be unit tested, and choose Properties.
  3. Go to the Deployment pane and enable the Enable Unit Testing property, as shown in Figure 3.44.
Figure 3.44

Figure 3.44. Enabling unit testing on project.

After enabling unit testing on the project, all maps in the project that are compiled will be inheriting from the TestableMapBase class in the Microsoft.BizTalk.TestTools.Mapper namespace instead of the normal TransformBase class in the Microsoft.XLANGs.BaseTypes namespace. The TestableMapBase class actually inherits from TransformBase, so nothing is lost. What is gained, however, are some methods and properties that can be leveraged for unit testing.

Next, you should add a test project to your solution. This is done by using the menu in Visual Studio 2010, where you can click Test, New Test to open the screen shown in Figure 3.45. In this screen, you can choose to either add the new test to an existing test project, if one is present in the solution, or create a new Visual C# test project. In addition, you can choose between four different tests:

  • Ordered Test: This gives you a way of orchestrating your tests, deciding what order they should be performed in.
  • Unit Test: This option gives you a class to write your tests in, but some manual work needs to be done like referencing the right assemblies and so on.
  • Basic Unit Test: This option provides an even smaller and simpler version of a unit test class than the unit test. More to implement yourself.
  • Unit Test Wizard: This helps you through some of the choices you must make, like what maps to test, and then generates the test class for you.

The other five options for adding a new test are not relevant for a BizTalk project.

For your first test project, name your file, choose Unit Test, and click OK. If you already have a test project, you can decide to add the file to an existing project by selecting it in the drop-down.

The test project is created for you, and it includes a pretty empty class for your tests. The class contains some definitions, methods, a constructor, and one method that is really the one thing to focus on, because this is the one you need to implement.

Figure 3.45

Figure 3.45. Adding a new test to your test project.

So, what you need to do in this method is to implement the unit test of the maps you want to test in this test class. Remember that you can have as many test classes and test methods in each test project as you want.

To test a map, you need to reference three different assemblies from your test project:

  • The assembly that contains the map: This assembly must have the Enable Unit Testing property set to True.
  • The Microsoft.BizTalk.TestTools assembly: This is found in the .NET pane of the Add Reference screen.
  • The Microsoft XLANG/s Base Types assembly: This is also found in the .NET pane of the Add Reference screen.

In the project, the XML instances that are to be used for the unit test can also be added. If you do this, consider marking their Build Action property to None, so they are not compiled needlessly into the assembly. The instances are not required to be included in the project, but it gives you a nice way of having everything needed for the test grouped together.

After adding the project references, you need to implement the test method. Locate the method in the class file called TestMethod1, and change it to something like the code shown in Listing 3.20.

Listing 3.20. Sample Test Method for Testing a Map

public void TestMapC1702OrderToFineFoodsOrder()
    string INPUT = testContextInstance.TestDir + @"\..\Order.xml";
    string OUTPUT = testContextInstance.TestDir + @"\..\MappedOrder.xml";
    TestableMapBase map = new Order_to_InternalOrder();
    map.ValidateInput = true;
    map.ValidateOutput = true;
    map.TestMap(INPUT, InputInstanceType.Xml,
        OUTPUT, OutputInstanceType.XML);
    Assert.IsTrue(File.Exists(OUTPUT), "File does not exist");
    // Read in OUTPUT and check relevant values.
    // Compare file with expected output.

The two strings INPUT and OUTPUT are declared to contain the path to the input instance for the map and the path to the output file to write the output to. The functionality required basically instantiates the map as a TestableMapBase class, which contains the needed properties and methods for unit testing. Then the properties ValidateInput and ValidateOutput are set to true. These properties mean the same as the properties you can set on the .BTM file and will determine whether the TestMap method should validate the input and output against the respective schemas before and after the map is executed. Any failures in this validation results in the test failing. Both values are false by default.

For the code to compile, the using statements shown in Listing 3.21 are needed. The namespaces are as follows:

  • Microsoft.VisualStudio.TestTools.UnitTesting: This is the namespace needed to use the TestClass and TestMethod attributes.
  • FineFoods.Customers.FamilyRestaurant: This is the namespace the map is located in, providing you access to the Order_to_InternalOrder class that is the compiled map.
  • Microsoft.BizTalk.TestTools.Mapper: This namespace contains the TestableMapBase class needed to call methods on the map object.
  • Microsoft.BizTalk.TestTools.Schema: This namespace contains the two enumerations used for specifying the type of input and the type of the output for the TestMap method.
  • System.IO: This is used to be able to access the File class that is used to check whether the output file exists in the assertion that is in the test method.

Listing 3.21. using Statements Necessary for Code in Listing 3.20

using Microsoft.VisualStudio.TestTools.UnitTesting;
using FineFoods.Customers.C1702;
using Microsoft.BizTalk.TestTools.Mapper;
using System.IO;

using Microsoft.BizTalk.TestTools.Schema;

The code in Listing 3.20 shows just one assertion, which basically asserts that the output file is created. You might need other assertions, such as comparing the output to an instance of the expected output or reading in the output file and validating some of the actual values created.

You should have as many instances as needed to make sure your map can handle all possible instances correctly. This means you should have plenty of input instances and possibly plenty of samples of the output.

You can find Microsoft’s description of the unit test features at http://msdn.microsoft.com/en-us/library/dd224279(BTS.70).aspx.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020