I was recently in a position where I had to justify why effort should be spent developing Stubbed Integration Tests for BizTalk solutions. These tests are usually developed using the BizUnit framework. I assumed that most seasoned BizTalk developers would consider this best practice. Even though Microsoft suggest use of BizUnit on MSDN, I've not found a single site listing the justifications for investing time writing stubs and BizUnit tests.
The industry average of writing unit testing code is around 30% of the original budget. This will also apply to BizTalk projects and BizUnit.
Stubs should be developed to isolate your BizTalk development team from external dependencies. This is described by Michael Stephenson here.
Failing to do this can result in the following problems:
- In contract-first scenarios, the external system interface will have been defined. But the interface may not have been setup or even developed yet for the BizTalk developers to work with.
- By the time you open the target location to see the data BizTalk has sent, it may have been swept away.
- If you are relying on the UI of the target system to see the data BizTalk has sent, what do you do if it fails to arrive? It may take time for the data to be processed or it may be scheduled to be processed later. Learning how to use the source\target systems and investigations into where things go wrong in these systems will slow down the BizTalk development effort.
- By the time the data is visible in a UI it may have undergone further transformations.
- In larger development teams working together, do you all use the same source and target instances. How do you know which data was created by whose tests? How do you know which event log error message are whose? Another developer may have “cleaned up” your data.
- It is harder to write BizUnit tests that clean up the data\logs after each test run.
- What if your B2B partners' source or target system cannot support the sort of testing you want to do. They may not even have a development or test instance that you can work with. Their single test instance may be used by the SIT\UAT teams.
- There may be licencing costs of setting up an instances of the external system.
The stubs I like to use are generic stubs that can accept\return any message type. Usually I need to create one per protocol. They should be driven by BizUnit steps to: validates the data received; and select a response messages (or error response). Once built, they can be re-used for many integration tests and from project to project.
I’m not saying that developers should never test against a real instance. Every so often, you still need to connect to real developer or test instances of the source and target endpoints\services. The interface developers may ask you to send them some data to see if everything still works. Or you might want some messages sent to BizTalk to get confidence that everything still works beyond BizTalk.
Automated “Stubbed Integration Tests” are usually built using the BizUnit framework. These facilitate testing of the entire integration process from source stub to target stub. It will ensure that all of the BizTalk components are configured together correctly to meet all the requirements. More fine grained unit testing of individual BizTalk components is still encouraged. But BizUnit provides much the easiest way to test some components types (e.g. Orchestrations).
Using BizUnit with the Behaviour Driven Development approach described by Mike Stephenson delivers the following benefits:
source: http://biztalkbddsample.codeplex.com – Video 1.
- Requirements can be easily defined using Given/When/Then
- Requirements are close to the code so easier to manage as features and scenarios
- Requirements are defined in domain language
- The feature files can be used as part of the documentation
- The documentation is accurate to the build of code and can be published with a release
- The scenarios are effective to document the scenarios and are not over excessive
- The scenarios are maintained with the code
- There’s an abstraction between the intention and implementation of tests making them easier to understand
- The requirements drive the testing
These same tests can also be used to drive load testing as described here.
If you don't do this ...
If you don't follow the above “Stubbed Integration Tests” approach, the developer will need to manually trigger the tests. This has the following risks:
- Developers are unlikely to check all the scenarios each time and all the expected results each time.
- After the developer leaves, these manual test steps may be lost. What test scenarios are there? What test messages did they use for each scenario?
- There is no mechanism to prove adequate integration test coverage.
A test team may attempt to automate integration test scenarios in a test environment through the triggering of tests from a source system UI. If this is a replacement for BizUnit tests, then this carries the following risks:
- It moves the tests downstream, so problems will be found later in the process.
- Testers may not check all the expected conditions within the BizTalk infrastructure such as: event logs, suspended messages, etc.
- These automated tests may also get in the way of manual tests run on these environments.