# How to test an Excel macro that selects, groups, and counts data using SQL query?

This is the first time I encountered such a problem.

There is an Excel table with a macro that selects data from the database using SQL query according to specific criteria. Data is grouped in different ways, then number of items is counted based on certain rules.

How it can be tested? Write my own queries to the database - I will check the database is working correctly :))

• This sounds like an interview question.
– user246
Jan 12, 2012 at 16:44
• No, I just have to test new functionality I never tested before. Jan 12, 2012 at 16:51

To motivate a point, I will describe two scenarios from a math class.

First, think back to when you took math tests in school. Sometimes your teacher asked you to check your work. One way to check your work is to calculate everything twice, but of course if you miscalculated because of a misunderstanding, you will probably get the same, wrong answer twice. Another way to check your answer is to calculate in a different way, or even better, to run the calculation backwards. So for example if you just calculated C = A + B, you check C by verifying that A = C - B.

Second, consider how a math teacher comes up with a test problem whose answer is a nice, round number. They have a choice: they can start with the nice round number and work backwards to determine the initial conditions, or do they can tinker with the initial conditions and recalculate until the initial conditions result in a nice round number.

Your choice is similar to the math teacher's: either (1) populate your database in such a way that you know what the report should produce, (2) use your own queries and your own calculations to determine what the spreadsheet should contain.