Sunday, October 6

How to invoke nUnit from Visual studio express and execute automation tests


nUnit is Unit testing framework tool for testing C# unit test cases. With the invent of selenium webdriver, this C# code intergrated with nUnit framework can be used to run acceptance tests. Simple way to integrate commands into Visual studio express to call nUnit tests is to use external tool feature.
Before that lets explore what options has nUnit has when you run it from a command line. Type ‘nUnit /help’ in command window which is in the directory where nUnit bin is pointing to, then it pops up below window .



image
Basically it has two types of argument. First is the name of inputfile which is the DLL file that you want to run. Second is the number of different options.
So if you type “nUnit <Projectname>.dll /run, this basically would open up nUnit and the project dll and start executing. This is exactly we want, but how to use this command from visual studio to avoid all other headache of entering path etc. That is by using external tool option and with just one click you can get nUnit tests executed from visual studio.
In visual studio express, go to Tools –> External tools. This Opens up a pop window with option to create a new external tool. Click on Button to Add this new tool and enter the options as shown in the screen shot
image
1. Enter title as Execute nUnit
2. In Command, click the button and browse to directory where nUnit.exe is stored and select it.
3. In Arguments text box , Enter the text as shown in the screenshot. “${BinDir}${TargetName}.dll /run”
4. In Initial director enter ${BinDir}
5. Select option prompt for arguments so that you can add additional options like categories if want to include. Then Apply and Ok.
After you have any nUnit tests created and complied, all you need to do is go to tools –>and click Execute nUnit (Click Okay on the prompt) and this would start nUnit and nUnit would load the dll file of the project you are on visual studio express and then start executing tests.
To add more flavor to above, say you require to run a particular tagged test instead of all the test cases in the dll. For that you need not go back to defining tool. As we chosen option to prompt for arguments, when you click Execute nUnit, the pop window allows you add the /include the tags you want or exculde the tags that you dont want to run as shown below. I have include the tests with a Tag attribute “NewTest”. The syntax of the argument that needs to be appended is
/Include:NewTest
or
/Exclude:Newtest
image

No comments:

Post a Comment

---------------------------------------------

Related Posts Plugin for WordPress, Blogger...