Managing test cases in Excel spredsheets is the most usual practice in test management. We all know the beauty and power that Excel provides. But, with Visual Studio Team System 2008, things are a little different. VSTS as it is called, uses a different file format for managing manual tests and also another major difference is, every manual test is a separate .mht file.
I was faced with this situation of converting all my excel based test cases into VSTS compatible manual test cases. I had around 500+ tests and converting them into VSTS manually would have probably taken more time than to develop them afresh.
I quickly pulled out a new C# project to do this task. It is pretty crude but works! and saved me days of manual work.
Solution
The solution is nothing but, data manipulation. I knew how my excel spreadsheet lays out test cases and what output format of VSTS manual test case. Read one line from Excel and spit out the data in MS Word saving the file with .mht extension. Simple right!
The excel looks like -
| Test ID | Title | Steps | Expected result | Priority | Method |
| 1 | Verify that… | 1. Launch the application 2. step2 3. step3 4. … |
Verify that… | BVT | API() |
| 2 | Verify that… | 1. Launch the application 2. step2 3. step3 4. … |
Verify that… | P1 | API() |
It really did not matter to me that my "generated" VSTS manual test cases fit exactly to the format shown in their sample. I used my own template (base) file which I will fill in with data read from the excel to create a new .mht file.
I have used a simple console application for this utility. You are going to need following references to be added to the project, mainly to work with Excel and Word.
- Microsoft Office 12.0 Object Library (COM)
- Microsoft.Office.Interop.Excel (.NET)
- Microsoft.Office.Interop.Word (.NET)
- Microsoft Visual Basic for Applications Extensibility 5.3 (COM)
Now, I have everything in single Main function, but you can always be a little smarter to split the code. I just wanted to put it to use as soon as I could :)
So, what I am doing here is, getting hold of the excel file first. I am going to dump all the files in a folder my local machine at "C:\Manual Tests".
Note: the last line in the below snippet is the most important. This is where you specify which "sheet" from the excel file you want to read. In this case is it the first one so specify get_Item(1). You can also put a bigger loop around to go through all the sheets in your excel file. I wanted to play safe!
As I mentioned earlier, I am using a template.mht to generate me test cases. I have placed the template.mht in the same folder where I want to dump the generated test cases. My template.mht is an "empty" word file with mht extension. You can have different sections in your template like Description, Title, Stetps, Expected results etc. and then fill the file accordingly. But that will need some more coding and I am not doing that here.
The only reason to create a .mht template is to give the output test case file its properties. For example, when you import any manual test case file with .mht extension in VSTS manual test project, the "Description" of that test case is read/populated from the "Title" property of that file. Why?, that's the way it is!
After having the hold of the excel file and the specific sheet, you have to define the ranage, the number of columns and rows to be read. The first for loop does just that. It is going to read from row 3rd till row 92nd for columns A to F.
While I read from this range, I also start splitting out the read data into separate .mht files. First I make a copy of template.mht, then open it for writing. I am using the sheet name + first column value to specify the name of the file. I even apply a font.
Once I have the newly made .mht file open, I write the column values one after the other from the current read row into the file. Here you can do all the formatting you wish for the output test case. Like, I am putting some extra text "Priority:" and "Method:" for those specific field values.
Once you are done dumping all the data, just save and close the file. If you import this file into VSTS, it would not show up "Description" in VSTS .vsmdi as we have not yet set it. Having the description helps me as my file names are not very descritpive.
Once the new .mht test case is ready, I hold it one more time. This time to update the "Title" property of the file as I know that is going reflect as "Description" in VSTS. One the way, I also set the "Author" property.
What happens at the end of this code? You get a bunch of .mht files which are equal to the number of test cases you have in your excel spreadsheet with their titles set correctly. Now, all you have to do is, open your VSTS project and import these file.
( 1 Vote )
| Comments |
|



























