- Posted by Jeremy Bokobza on October 12, 2009
I’ve always been afraid to use BizUnit.
It seemed like a lot of work had to be done before I could actually test anything so I never really bothered to look into it.
I was recently on a project where testing any functionality was a very very long process.
Put some files somewhere, check some emails, go to a website, check SQL tables … you know the drill.
At some point I had enough and decided to see what all the fuss about BizUnit was about.
Let me tell you that from now on, this is how I’ll do testing.
The documentation is clearly not the best in the world, so I’ve cooked a very simple example for anyone interested to start using BizUnit.
The little solution
The solution in this example is very simple:
BizTalk picks up a file from a folder location, applies a little transformation, and send the result to another location.
I could have done it without an orchestration, but I still used one for you guys to add some functionality to it if you wanted to extend the example a bit.
![clip_image001[5] clip_image001[5]](http://www.mavenlog.com/image.axd?picture=WindowsLiveWriter/FirstStepswithBizUnit_B1A9/clip_image001%5B5%5D_thumb.png)
0. Installation of BizUnit
You can download it here and install it following the installation steps – nothing fancy here.
1. Identify the steps required for testing
After you’ve implemented and deployed your BizTalk solution and that you’re ready to test it, you need first of all to identify the steps required for testing:
- Do you need to put some files in a folder for BizTalk to pick up?
- Do you need to validate some data in those files first?
- Do you need to see if some rows got successfully inserted in some SQL tables?
Basically, write down all you need to check for your test to be declared successful.
For my little solution, I have 5 steps:
1. Delete all the files present in the receive location
2. Put a file in the receiving location
3. Wait 10 seconds – give time to Biztalk to do its business
4. Check there is a file in the send port location
5. Delete the file in the send port location
2. Create the Test Cases
A TestCase is an XML file that declares all the steps described in the section above.
It consists of 3 distinct parts:
- TestSetup – this stage is used to setup your environment (here we’ll do step 1)
- TestExecution – this stage will do the actual test (here we’ll do step 2, 3 and 4)
- TestCleanup – this stage will cleanup the environment to leave it as it was. (here we’ll do step 5).
Note that this stage will execute even if the previous stages fail.
Each of these stages has 0, 1 or multiple TestSteps which represents the actual steps we described above.
The basic structure of a TestCase is like this:
<TestCase testName="Test_01">
<TestSetup>
<TestStep assemblyPath="" typeName="">
</TestStep>
.
.
.
</TestSetup>
<TestExecution>
<TestStep assemblyPath="" typeName="">
</TestStep>
.
.
.
</TestExecution>
<TestCleanup>
<TestStep assemblyPath="" typeName="">
</TestStep>
.
.
.
</TestCleanup>
</TestCase>
Each of the TestSteps has a typeName attribute and some parameters as element.
The typeName tells us what function to execute and the parameters are parameters of this function.
You create all the steps you need in the stages where they must be executed.
For example, to copy a file from a folder to another, the testStep will look like this:
<TestStep assemblyPath="" typeName="BizUnit.FileCreateStep">
<SourcePath>source.xml</SourcePath>
<CreationPath>destination.xml</CreationPath>
</TestStep>
For deleting files from a folder the function is BizUnit.FileDeleteMultipleStep, to add a delay it is BizUnit.DelayStep etc…
There are functions for almost everything.
It’s a bit of a hassle because there isn’t any structured XML so you don’t have intellisense here.
The place to go and look at if you’re looking for a method is the BizUnit.chm (located in C:\Program Files\BizUnit\BizUnit 3.1\bins).
If you’re interested in how any method operates, you should look into the BizUnit solution (located in C:\Program Files\BizUnit\BizUnit 3.1) where most of them are.
3. Create a test project (if you do tests with Visual Studio) or a class library (if you use NUnit)
Add a test project and then add a reference to the BizUnit assembly (C:\Program Files\BizUnit\BizUnit 3.1\bins\BizUnit.dll)
Then add 1 TestMethod per XML TestCase file.
We have one TestCase XML for our tests so we have only one test method.
In the TestMethod, the code to invoke BizUnit looks like this:
[TestMethod]
public void TestMethod1()
{
BizUnit.BizUnit bizunit = new BizUnit.BizUnit(@"path\TestCase_01.xml");
bizunit.RunTest();
}
4. Run your tests
Once you’ve done all the above, you’re ready to test.
Run your test and check that it passed.
If you click on the Test Result row, you can see the output of the tests in the Standard Console Output.

I hope this helps in starting with BizUnit.
The source code for my example is provided below.
It includes everything you need for our example : the BizTalk project, the test project, the TestCase, the binding file (for the ports) and the test file and folders.