Geeks With Blogs

News View Michael Stephenson's profile on BizTalk Blog Doc View Michael Stephenson's profile on LinkedIn
Michael Stephenson keeping your feet on premise while your heads in the cloud
I'm not sure about anyone else but when I come across something that is boring and repetitive I usually get around to doing some tool that minimizes the amount of time I spend doing it. In this case the task that is boring me is writing the repetitive C# code to call BizUnit to make it run your tests. I'm sure there are lots of different ways you could do this but one day when I was stuck waiting for a while at the airport I got bored and decided to do something to stop me having to do this. 
 
Aim
 
The aim of the tool was as follows:
 
  1. Don't write anymore C# code to call BizUnit tests, I want to generate it
 
  1. Maintain a simple list of tests which can be easily updated
 
  1. Include the tool in the build process so that any newly added tests have the appropriate C# code created
 
Design Decisions
 
I made the following decisions about the tool I would create:
 
  1. I decided to make an MsBuild task so it would easily plug into the build process and also regenerate the C# each time
 
  1. I decided to use an xml list of the tests. I could have looked for files which were BizUnit tests but this would probably need to have some kind of file naming convention.
 
  1. I wanted to wrap the call to BizUnit with a try/catch block so I could log the error to the event log. This is particularly useful when you run the tests from the command line and you don't see all of the failure details.
 
  1. The task would be easily configurable so it could use Nunit or MsTest to run the tests.
 
Using the Task
 
Before I get into how I built the task I think if I explain how it is used it should seem simple and easily usable. We have used this task on a couple of projects and it has been quite handy.
 
To begin with we have the below image from the sample project. In this picture you can see the following things:
 
  • A folder containing 3 BizUnit definition files

 

  • The BizUnitTestDefinitions.xml file which describes the tests within the project and determines the code that will be generated.

 

  • The OverrideBuild.targets file which is imported by the project file and contains overrides for some of the build events (more on this later)

 

  • The BizUnitTests.cs file which is the code file which gets generated

 

 

BizUnitTestDefinitions.xml
As I mentioned this file is the one that describes the tests within the project. The below picture shows an example of this xml.

 

The key points of the xml are as follows:
 
  • The TestGroup element allows you to group related tests. Each TestGroup will produce a class containing tests. The Name attribute will become the name of the test class.

 

  • Each Test element will become a method which will run a test. It will be contained within the class from its associated TestGroup. The Name attribute will become the name of the test

 

  • The BizUnitTestCasePath element will point to the file containing the details of the BizUnit test. In this case because the example project uses MsTest I have copied the BizUnit tests to the test results directory using the TestRunConfig so I dont need to worry about the path.
 
OverrideBuild.targets
This file is imported by the project file allowing me to specify MsBuild targets to customise the projects build process. The contents of this file are below:
 
 
In this file I have a target which overrides the BeforeBuild target. This is because I want to generate the class containing my tests before the project is compiled.   The key points of this file are:
 
  • The UsingTask element imports my custom MsBuild task so I can use it

 

  • The use of my task in this case is set to use MsTest, but you could easily use Nunit instead by specifying the appropriate values for the TestAssemblyName, TestFixtureAttributeName and TestMethodAttributeName.
 
This task will basically take these parameters and inspect the xml definition of the tests then produce the output file containing the C# code.
 
BizUnitTests.cs
This file contains the code which is generated. An example of some generated code is in the picture below:
 
 
The couple of key points to note are: 
  • I have made it generate code which will log to the event log any errors to make troubleshooting easier
  • If you use source control you might want to exclude this file from source control so it can be regenerated each time you build the project.
 
Summary
 
If there is any interesting feedback on this post I will probably do a follow up describing how the MsBuild task is build. In the meantime the code for the task, and also the sample project are available at the below location so you should be able to see this for yourself.
 

Disclaimer

I have noticed a few sites that seem to copy the content of blog articles and display them in their own site.  It is a bit annoying that they do not clearly reference or acknowledge the author so I have decided to put this note on the bottom of all of my posts from now so it is clear who wrote it.

This article was written by: Michael Stephenson

The source of this article is: http://www.geekswithblogs.net/michaelstephenson

Posted on Saturday, January 19, 2008 11:05 PM BizTalk , MsBuild | Back to top


Comments on this post: Generating the C# to call BizUnit Tests

# re: Generating the C# to call BizUnit Tests
Requesting Gravatar...
Michael,
Very interesting work. I was planning to write an add-in to generate the C# file. We have a standardised project template for BizUnit (and Extensions) projects so it should be quite easy to do it. Your work looks pretty cool too.

cheers
Left by Benjy on Feb 23, 2008 7:42 PM

# re: Generating the C# to call BizUnit Tests
Requesting Gravatar...
Nice idea.
I'll try the same using T4, could be less intrusive.
Left by GiulioV on Nov 13, 2009 7:31 AM

# re: Generating the C# to call BizUnit Tests
Requesting Gravatar...
When clicked on the link to your code I get "This folder does not have any files in it. If you think this is a mistake, please contact the folder owner." I wanted to use this.
Left by Art on Feb 10, 2011 10:01 AM

# re: Generating the C# to call BizUnit Tests
Requesting Gravatar...
I will probably do a follow up describing how the Ms Build task is build. In the meantime the code for the task, and also the sample project are available at the below location so you should be able to see this for yourself Pizza Hut store hours

Left by komal on Jun 21, 2017 4:30 PM

# re: Generating the C# to call BizUnit Tests
Requesting Gravatar...
Thanks for sharing nice post please do share such please share with us USPS Saturday hours
Left by komal on Jun 23, 2017 10:24 PM

# august 2017 calendar
Requesting Gravatar...


If you are going to out side you home and make journey then this website will be very helpful.
august 2017 calendar template
Left by naitikkumar on Jul 01, 2017 3:14 AM

# re: Generating the C# to call BizUnit Tests
Requesting Gravatar...

If there is any interesting feedback on this post I will probably do a follow up describing how the MsBuild task is build. In the meantime the code for the task, and also the sample project are available at the below location so you should be able to see this for yourself. Medium Length hairstyles thankyu
Left by demo on Jul 02, 2017 7:31 PM

# re: Generating the C# to call BizUnit Tests
Requesting Gravatar...
Use impacts as well as filters, as well as share instagramloginway Faucet Places for leading places.
Left by donald on Oct 02, 2017 10:46 PM

# myloweslife
Requesting Gravatar...
The last, you need to tap the gray login switch to process your login. my lowe's life directly from your income.One need's not to pay government tax
Left by Lambert on Nov 29, 2017 8:36 PM

# re: Generating the C# to call BizUnit Tests
Requesting Gravatar...
The significant title on the web site could be checked out as L'Brands Access for many acesetm In the Limited eliminated its possession from the A&F brand.
Left by qualisian on Jan 11, 2018 7:16 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Stephenson | Powered by: GeeksWithBlogs.net