September 29, 2006

Testing 1-2-3... is this thing on?

1.1 What are These Strange Creatures?

I have to say that tests are such a straight-forward concept that it’s actually harder to describe what they are than it is to show you how to do them.

So what are tests?

The Official Answer

Tests are collections of questions and scenarios that provide us (developers) with consistent results which prove that our application is doing what we expect it to do.

The Unofficial Answer

We write tests to interrogate, taunt, bully, punish, and otherwise kick the crap out of our application code until it consistently gives us the correct answer. Think of it as “tough love”. ;)

Need some examples?

* ensure user names have at least 4 characters
* ensure that when we save this record, the administrator is e-mailed
* ensure all replies are deleted when we delete the parent message
* ensure that Canadians have GST of 7% applied to their purchases

The idea of tests is that you write them at the same time as you write your application. In essence, you’re writing two application. As your application grows and becomes more complex, you create many tests. Re-running these tests at any point will help you discover if you’ve “broke” anything along the way.

Some developers actually take this a step further and create the tests before they create the application. This is called Test Driven Development (TDD), and although I personally don’t subscribe to it, it’s a totally legit way of coding.

There’s volumes written about Test Driven Development and testing in general. For more information, talk to Mr. Google.

1.2 So Why Test?

As mentioned before, tests offer proof that you’ve done a good job. Your tests become your own personal QA assistant. If you code your tests correctly, at any point in development, you will know:

* what processes work
* what processes fail
* the effect of adding new pieces onto your application

With your tests as your safety net, you can do wild refactoring of your code and be able to tell what needs to be addressed simply by seeing which tests fail.

In addition to normal “did it pass?” testing, you can go the opposite route. You can explicitly try to break your application such as feeding it unexpected and crazy input, shutting down critical resources like a database to see what happens, and tampering with things such as session values just to see what happens. By testing your application where the weak points are, you can fix it before it ever becomes an issue.

A strong suite of tests ensures your application has a high level of quality. It’s worth the extra effort.

Another positive side-effect of writing tests is that you have basic usage documentation of how things work. Simply by looking at your testing code, you can see how you need to work with an object to make it do it’s thing.

But enough about theory.

FROM: Ruby on Rails

The Benefits of Automation and Tools

Think back to what you've learned about how software is created. In most software development models, the code-test-fix loop can repeat several times before the software is released. If you're testing a particular feature, that means you may need to run your tests not once, but potentially dozens of times. You'll check that the bugs you found in previous test runs were indeed fixed and that no new bugs were introduced. This process of rerunning your tests is known as regression testing.

If a small software project had several thousand test cases to run, there might be barely enough time to execute them just once. Running them numerous times might be impossible, let alone monotonous. Software test tools and automation can help solve this problem by providing a more efficient means to run your tests than by manual testing.

The principal attributes of tools and automation are:
* Speed. Think about how long it would take you to manually try a few thousand test cases for the Windows Calculator. You might average a test case every five seconds or so. Automation might be able to run 10, 100, even 1000 times that fast.
* Efficiency. While you're busy running test cases, you can't be doing anything else. If you have a test tool that reduces the time it takes for you to run your tests, you have more time for test planning and thinking up new tests.
* Accuracy and Precision. After trying a few hundred cases, your attention span will wane and you'll start to make mistakes. A test tool will perform the same test and check the results perfectly, each and every time.
* Resource Reduction. Sometimes it can be physically impossible to perform a certain test case. The number of people or the amount of equipment required to create the test condition could be prohibitive. A test tool can be used to simulate the real world and greatly reduce the physical resources necessary to perform the testing.
* Simulation and Emulation. Test tools are often used to replace hardware or software that would normally interface to your product. This "fake" device or application can then be used to drive or respond to your software in ways that you chooseand ways that might otherwise be difficult to achieve.
* Relentlessness. Test tools and automation never tire or give up. They're like that battery-operated bunny of the TV commercialsthey can keep going and going and…

All this probably sounds like great news. You could have test tools do all the work for youturn them loose and wait for the results. Unfortunately, it's not that easy. Houses aren't built automatically, even though carpenters have power saws and nail guns. The tools just make it easier for them to do their work and for the resulting work to be of higher quality. Software test tools operate the same way.

NOTE:
Software test tools aren't a substitute for software testersthey just help software testers perform their jobs better.

It's important to note that using test tools isn't always the right answer. Sometimes there's no substitute for manual testing. For now, take in the information about what tests tools can do and how they work. Think about how you might use them to complement your testing tasks.

September 25, 2006

Sample post

Woo, do you like this page?

-rogerw.hai