Share via


Minor fixes (tweaks) to some test code

One of the automated tests I own had a failing result a few weeks ago and in the process of fixing it I updated quite a bit if our test code.

First, the test that failed was one that uses the arrow keys to move lines of items in a list up and down within the list. You can do this yourself with SHIFT+ALT+ UP or Down.

Suppose you have this list:

Chihuahua

Capybara

Rodent

And you want them to be alphabetically ordered. The easiest way to do this is to put focus on either Chihuahua and move it down, or on Capybara and move it up. Go ahead and click either item and then type SHIFT+ALT+UP (if you selected Capybara) or SHIFT+ALT+DOWN (if you selected Chihuaha). You get this:

Capybara

Chihuahua

Rodent

This really makes you look like a power user if you do this during a meeting. Anyway, as I was adjusting the test to avoid using the SendKeys method that was not working for me, I noticed that a lot of the methods in our test code were throwing the incorrect type of exception if required prerequisites were not met. For instance, in my test case, I need to have a page on which to work. If there is no page - for instance, if the test was in a section that has no pages - then the test would fail, so I want to check for that before the rest of my test code runs. If there is no page, I want to throw a "Pre-Check" exception so that if I need to investigate the failure later, I know it was a prerequisite that was not met.

I did that, but when I looked through the rest of the code, I noticed a set of methods that were throwing "InvalidOperationExceptions" in this case. I had a choice here - either leave the code alone or fix it. The case for leaving it alone is pretty obvious - the only person that would notice this would be the test owner when investigating a failing test and if that tester is OK with this, just leave it alone. The case to fix it is that this violates our coding guidelines.

I decided to go ahead and perform this slight refactor and made the needed changes. Now my change is up for a review and I will see if others want to accept this change which actually has nothing to do with my fix.

I'll keep you posted if you are interested in the outcome.

Questions, comments, concerns and criticisms always welcome,

John