Tuesday, March 18, 2008

BizUnit 3.0 Api

Lately I've been working heavily with the BizUnit 3.0 beta for testing a number of different projects. In particular I'm consuming the new object model API in order to programmatically invoke tests using a variety of test sources. The purpose of this post is to provide an introduction to the new API and it's usage. Prior to 3.0, BizUnit needed to be invoked using XML such as the following (an example borrowed from the CodePlex site):

<TestStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.FileValidateStep">
  <Timeout>3000</Timeout>
  <Directory>..\..\..\Rec_03\</Directory>
  <SearchPattern>TransactionId_*.xml</SearchPattern>
  <DeleteFile>true</DeleteFile>
 
  <ValidationStep assemblyPath="" typeName="Microsoft.Services.BizTalkApplicationFramework.BizUnit.XmlValidationStep">
      <XmlSchemaPath>..\..\..\TestData\PurchaseOrder.xsd</XmlSchemaPath>
      <XmlSchemaNameSpace>http://SendMail.PurchaseOrder</XmlSchemaNameSpace>
      <XPathList>
          <XPathValidation query=
              "/*[local-name()='PurchaseOrder' and namespace-uri()='http://SendMail.PurchaseOrder']
              /*[local-name()='PONumber' and namespace-uri()='']">PONumber_0</XPathValidation>
      </XPathList>
  </ValidationStep>  
</TestStep>

BizUnit could then be invoked with something like the following (where BizUnitAPI is the BizUnit class in the BizUnit namespace):

string myConfigFile = "c:\path\to\test.xml"; BizUnitAPI bizUnit = new BizUnitAPI(myConfigFile); bizUnit.RunTest();

This is great because we can easily generate XML to represent a set of Test Cases and Test Steps to run in series. However, this doesn't give you the control you might need. Enter the BizUnit.BizUnitOM namespace and it's new classes:

  • BizUnitTestCase : Encapsulates a set of test steps.
  • TestStepBuilder : Builds a test step instance.
  • ITestStepOM : Test step classes must implement this to work with the new API.

Our usage of the API can be written as follows:

  1. Create a BizUnitTestCase.
  2. For each step:
    1. Create a TestStepBuilder.
    2. Set each of the properties of the test step to ensure the step behaves as we want.
    3. Add the TestStepBuilder to our test case.
  3. Create a BizUnit instance using the BizUnitTestCase.
  4. Run the test.

The following is a trivial example of creating a test case to delete all the TXT files in a specified path.

BizUnitTestCase testCase = new BizUnitTestCase("My First Test Case");

TestStepBuilder testStepBuilder = new TestStepBuilder("BizUnit.FileDeleteStep");

object[] args = new object[1] {@"c:\my\path\*.txt"};

testStepBuilder.SetProperty("FilesToDeletePath", args);

testCase.AddTestStep(testStepBuilder, TestStage.Execution);

BizUnitAPI bizUnit = new BizUnitAPI(testCase);

bizUnit.RunTest();

If the test step were to require multiple arguments to be set, then the SetProperty method can be called as many times is required. Also, a TestStepBuilder needs to be generated for each test step in our test case.

If the required implementation of ITestStepOM is not included with BizUnit, then the TestStepBuilder can be invoked to load an external assembly:

TestStepBuilder testStepBuilder = new TestStepBuilder("MyAssembly.MyTestStep", "c:\path\to\MyAssembly.dll");

Note that, out of the box, only certain property types are supported as test step properties. These are:

  • double
  • bool
  • short
  • int
  • long
  • string
  • IList<string>
  • IList<Pair>

Other types can be supported but they require a custom implementation of ITestStepParameterFormatter. The implementation of which I'll save for another post.

Any questions or comments? I recommend the CodePlex Discussions Page.

Friday, March 14, 2008

Keeping Track

One of the problems of using a variety of online services is how do your friends keeping track of what you are doing. Facebook solves this, for people that haven't discovered RSS, in it's News Feed feature. However, I'd much rather read in the comfort of my familiar RSS reader than on Facebook. This is where FriendFeed comes in. FriendFeed aggregates the feeds from all the services you use. Short-form updates from Twitter, long form updates from your blog, favourite tracks from Last.FM, shared links on del.icio.us are all combined into a single feed. Users can choose to read the feed on FriendFeed.com or can subscribe to the aggregated feed in their RSS reader. As long as you keep your services in FriendFeed up-to-date, your friends will only ever need to subscribe to 1 feed for all of your online activity. Give it a try. You can find my feed here.