Testing Can Save Time

for RuBoard

"How?" you ask. By reducing the amount of time you spend debugging. By building tests into your code, and structuring these tests so that they check themselves , you create a test that is as easy to run as the application itself. When tests are easy to run, you'll find yourself running them all the time. Each successful test will give you a little jolt of confidence in your code. You'll also uncover bugs earlier and fix them more easily than you'd be able to without constant testing. All told, you'll spend far less time debugging, and will therefore develop better code more quickly.

It's a common misconception that most of the time spent developing software is spent coding. Actually, more time is spent debugging than coding in the typical project. [6] If you can reduce this through automated, self-checking tests, you can shorten the development cycle dramatically.

[6] McConnell. After the Gold Rush . Redmond, WA: Microsoft Press, 1999. Page 11.

How do you build self-checking tests into your code? Every class should have a test method that you can call to check the class. This test should quickly check every functional aspect of the class. Rather than writing the output of the test to the console or to a file, embed the expected output in the test method, then code the method such that it checks its output against the expected results. If the two compare correctly, display a message that says, OK or Tests Successful. If not, display a failure message. This way, you let the computer do what it does bestrepetitive, relatively mundane (but critical) tasks .

You can automate the testing of several units at once (and even entire applications) by using automated testing tools. There are several of these available, many with features to test user interfaces as well as the code behind them. Most expose an API that allows an application to identify its built-in test harness, if it has one. These types of tools are often very sophisticated, sporting such advanced features as scripting languages, code analysis, and debugging aids. If you work on large projects, tools like these are a must.

Be careful when writing test methods. Poorly written or incomplete test methods are like a set of rose-colored glasses : They hide potential ugliness and misbehavior in your code. [7] Test methods serve to ensure the solidity of your system, so be sure they're solid themselves.

[7] Beck, Kent. Extreme Programming Explained: Embrace Change . Reading, MA: Addison-Wesley, 2000. Page 47.

for RuBoard


The Guru[ap]s Guide to SQL Server[tm] Stored Procedures, XML, and HTML
The Guru[ap]s Guide to SQL Server[tm] Stored Procedures, XML, and HTML
ISBN: 201700468
EAN: N/A
Year: 2005
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net