Automated Testing of
Excel Workbooks
Felix Zumstein, 18 June 2019
xlwings Meetup London
From unit tests to continuous integration
Agenda
2
1. Introduction
2. Meetup organisation
3. xlwings intro
4. Talk: Automated Testing
5. Pub
1. Introduction
Innovative Solutions
for Microsoft Excel
A small team with a big mission
4
Our Solutions (1/2)
Python for Excel
>>> import xlwings as xw
>>> xw.Book()
<Book [Book1]>
5
Version Control for Excel
Our Solutions (2/2)
6
git-xltrail
CI
(pilot)
Git extension for VBA
Continuous Integration
for Microsoft Excel
2. Meetup Organisation
Meetup Organisation
8
• Community event
• About any innovative solution for Excel,
not just those based on xlwings
• Contact me if you want to give a talk
(short or long) in one of the next
meetups
3. xlwings Intro
xlwings
10
1) Automation
2)Macros
3)UDFs (Windows only)
4)REST API
Except for UDFs, everything works on Mac
and Windows and requires an installation
of Excel.
4. Automated Testing
What is a unit test (Python sample)?
12
Python function
that we want to test
Unit test:
OK or FAIL
Map VBA functions to Python
13
VBA function
Calling the
VBA
function
from Python
VBA unit test boilerplate
14
run at the
beginning
and end of
the test
suite,
respectively
actual test
What can be tested in Excel?
15
1) Unit test: E.g. a cell formula, a VBA function
or an xlwings UDF
2) Integration test: E.g. running an entire
macro or testing the effect of a cell change
on the whole workbook
3) Cell logic test: Test dynamic tables
4)Alternative implementation test: E.g.
comparing a VBA function with a function
available in (a tested) 3rd party library
1a) VBA unit test
16
1a) Cell formula unit test
17
2) VBA integration test
18
3) Cell logic test
19
4) Alternative Implementation Test
20
Run the tests
21
To run a single test:
python -m unittest test_mybook.TestMyBook.test_vba_unittest
Unittest runners/frameworks
22
1) unittest: built-in
2) pytest
3) nose/nose2
Continuous Integration (1/2)
23
1) Use Git for version control
2) The tests are automatically run on a server
whenever you push a new version
Continuous Integration (2/2)
24
Thank You

Automated Testing of Excel Workbooks