Question posted 2010 · +7 upvotes
are there any good frameworks that can help unit test code in excel ?
Accepted answer +5 upvotes
I assume you want to unit test VBA code in modules.
First, even if there was a good unit testing framework available for VBA, I suspect testing would be very complex, because of the dependencies to the Workbook itself. If your code interacts with the workbook and its objects is going to be a total nightmare because you can’t really mock any of this: imagine testing a module that reads data in a sheet and creates a chart in another one… In essence, an Excel workbook merges your persistence, domain and presentation all in one – not good for testing.
The other case is code which is mostly computation oriented. If that code gets complex enough that it warrants testing, one thing you might consider is to actually move your code outside of VBA, to make it testable. I often work with clients who have large financial models, with heavy VBA, and when I can I like to extract the VBA code to C# and make it a VSTO add-in. The benefit is that I can test the code, and work in Visual Studio, instead of the VBA IDE.
Top excel Q&A (6)
- Shortcut to Apply a Formula to an Entire Column in Excel +335 (2011)
- How should I escape commas and speech marks in CSV files so they work in Excel? +136 (2012)
- Convert xlsx to csv in linux command line +96 (2012)
- How to create a link inside a cell using EPPlus +50 (2011)
- IF statement: how to leave cell blank if condition is false ("" does not work) +44 (2013)
- T-SQL: Export to new Excel file +44 (2012)
excel solutions on this site
.