Reputation: 8001
How to unit test an Excel Workbook project?
I use Visual Studio 2012 C#.
I have read several posts so far, and it seems I can't simply create a unit test project and then reference the main excel workbook project, because it depends on interop excel.
Is this a valid solution, and if not can you please give suggestions:
1) I can separate my main project in two: excel workbook project + dll project that will contain the logic. The excel workbook project will reference the dll project.
2) Then I can create unit test project and reference the dll project. I can create my own excel files and create unit tests for my excel reading functions, that are in the dll project.
Upvotes: 1
Views: 4159
Reputation: 9499
It depends if you want to test the :
for both the cases, you don't need to separate out the project into Main & Library. A single project with rightly separated logic should be good enough. And by rightly separated logic, i mean interface based classes to do Excel stuff that don't interfere with testing etc.
now for #1, from the unit test:
for #2, from the unit test:
ensure the workbook is deleted in either cases.
the only difference between #1 & #2 is that you unit test one more level of code.
e.g. You Main logic will be:
public static void MainLogic()
{
string workbookFileName = ""; // read workbook path from config etc.
// validate anything
CoreClass.CreateWorkbook(workbookFileName);
// you could do additional stuff here.
}
and your sample unit test is:
[Test]
public void MainLogicTest()
{
string workbookFileName = ""; // read workbook path from test config etc. but same path.
MainLogic();
// retrieve the workbook at workbookFileName and verify.
}
Upvotes: 2