1 / 17

Unit Testing BizTalk

Learn how to overcome the challenges of unit testing in BizTalk by using BizMock, a framework that allows you to "mock-up" BizTalk endpoints and perform richer unit testing. This intro guide explains the setup process and provides an overview of the key artifacts needed.

lcross
Download Presentation

Unit Testing BizTalk

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit Testing BizTalk An Intro to BizMock

  2. Difficulties in Unit Testing BizTalk The Value of Test-Driven Development is well-known. However, doing it in BizTalk can be difficult: • SOA and ESB solutions are loosely-coupled by design and as a result, difficult to test. • Testing can usually take place only after external solutions are available and online. • Most pieces of a BizTalk solution (such as pipelines, orchestrations, .dll’s) perform only narrow and specific tasks with many follow-on dependents. • Most BizTalk unit tests simply involve the act of copying a file to one location and picking output up from another.

  3. BizMock as a Unit-Test Utility Available at http://bizmock.codeplex.com BizMock allows us to overcome many of the difficulties in unit-testing BizTalk by providing a framework to “mock-up” BizTalk endpoints. BizMock works with BizTalk as a special adapter that sends and receives messages into and from the BizTalk system Ports and other artifacts can be dynamically generated and removed at runtime. BizMock exposes a number of test functions which allow for richer BizTalk unit-testing than can be done in the typical “file drop” scenario.

  4. BizMock Drawbacks The number one drawback of using BizMock is that it is very poorly documented. To understand how it works, you’ll need to spend a great deal of time studying BizMock’s source code, which is available in the CodePlex download.

  5. Setting It Up • Deploy your BizTalk assemblies (orchestrations, pipelines, maps, schemas) • Create a test project and add BizMock assembly references: • BizMockArtifactsSchema • BizMockery • BizMockMessaging • BizMockReceiveAdapter • BizMockSamples • Add artifacts.tt and artifacts.xml from the Sample project to your test project • Modify artifacts.xml to reflect your artifact definitions • Execute the template to generate your code • Write unit tests

  6. Artifacts.xml Overview

  7. Artifacts.xml: Custom Types • Message Verifiers : Validates messages against schema and property. • Single Message Verifiers • Multipart Message Verifiers

  8. Artifacts.xml: Custom Types (cont’d) • Message Instances • Single Message Instance • Multipart message Instance

  9. Artifacts.xml: Artifacts • Artifacts element Attributes: • name: choose the name you wish your artifacts collection class to be called in code. For most purposes, the default value , “Artifacts”, is a pretty good choice. • appName: the name of the BizTalk application that artifacts will be deployed to for testing. • Message Instances <MessageInstance>        <Name>Msg_Simple</Name>        <Type>SimpleMessageType</Type>        <Files>          <File>SimpleSchema_input.xml</File>        </Files> </MessageInstance> • Message Verifiers <MessageVerifier>    <Name>Vrf_Simple</Name>    <Type>SimpleSchemaTypeVerifier</Type> </MessageVerifier>

  10. Artifacts.xml: Artifacts (cont’d) • Maps <Map>    <Name>xyzMap</Name> <MapFullName>BizMock.Samples.xyzMap</MapFullName></Map> • Ports • Two-Way Send <TwoWaySendPort>    <Name>GetDataService</Name>    <PortName>GetDataService</PortName>    <SendPipeline>          <Name></Name>          <Data></Data>    </SendPipeline>    <ReceivePipeline>         <Name></Name>         <Data></Data>    </ReceivePipeline>    <Dynamic>true</Dynamic></TwoWaySendPort>

  11. Artifacts.xml: Artifacts (cont’d) • Ports • One Way Receive <OneWayReceiveLocation>      <Name>OWPort_1</Name>      <PortName>OWPort_1</PortName>      <ReceivePipeline>          <Name></Name>    <Data></Data>      </ReceivePipeline></OneWayReceiveLocation> • Databases <Database>     <TypeName>DatabaseArtifact</TypeName>  <Name></Name> <ConnectionString></ConnectionString></Database>

  12. Artifacts.xml: Artifacts (cont’d) Event Log <EventLog>    <Name>BizMock_EventLog</Name>    <Log>Application</Log>    <Source>BizMock</Source></EventLog> Orchestration <Orchestration>    <Name>MultipartWithLoopOrchestration</Name>    <FullName>BizMock.Samples.MultipartWithLoop</FullName>    <Ports>     <Port>         <Logical>Port_1</Logical>          <Physical>OWPort_1</Physical>        </Port>        <Port>          <Logical>Port_2</Logical>          <Physical>OWPort_2</Physical>        </Port> </Ports></Orchestration>

  13. Writing BizMock Unit Tests Add test documents to your project Call the Initialize() method of your artifacts class in the ClassInitialize() or TestInitialize() method of your testing class Call BizMockery.DeleteAllInstances() in your ClassCleanup() method. In each TestMethod, be sure to add a DeploymentItem for each test document used.

  14. Sample Test [TestMethod][DeploymentItem("SimpleSchema_input.xml")][DeploymentItem("SimpleSchema2_input.xml")][DeploymentItem("Service1_request.xml")]publicvoidMultipartWithLoopTest(){artifacts.MultipartWithLoopOrchestration.Start();artifacts.Msg_MultiPart.InterchangeID = "X";//art.Vrf_Multipart.MultiPart1.Field = "Y"; //art.Vrf_Multipart.MultiPart2.Field = "Y";Submit.Request(artifacts.Msg_MultiPart).To( artifacts.OWPort_1);Expect.AtLeast(2).Request.At(artifacts.OWPort_2).Verify( artifacts.Vrf_Multipart);}

  15. Demo

  16. Contact Info • Ed Jones, MCT, MCPD, MCTS • Email: talentedmonkey@hotmail.com • Blog: Extremely Talented Monkeyshttp://talentedmonkeys.wordpress.com

  17. THANK YOU!

More Related