WELCOME, GUEST
Minimize
Blogger List

Steven Feuerstein Indicates Oracle ACE director status
PL/SQL Obsession

Guy Harrison Indicates Oracle ACE status
Database topics

Bert Scalzo Indicates Oracle ACE status
Toad for Oracle, Data Modeling, Benchmarking
Dan Hotka Indicates Oracle ACE director status
SQL Tuning & PL/SQL Tips

Valentin Baev
It's all about Toad

Ben Boise
Toad SC Discussions

Dan Clamage
SQL and PL/SQL

Kevin Dalton
Benchmark Factory

Peter Evans 
Business Intelligence, Data Integration, Cloud and Big Data

Vaclav Frolik  
Toad Data Modeler, Toad Extension for Eclipse

Devin Gallagher
Toad SC discussions

Anju Gandhi
Toad for Oracle

Stuart Hodgins
JProbe Discussions

Julie Hyman
Toad for Data Analysts

  Henrik "Mauritz" Johnson
Toad Tips & Tricks on the "other" Toads
  Mark Kurtz
Toad SC discussions
Daniel Norwood
Tips & Tricks on Toad Solutions
Amit Parikh
Toad for Oracle, Benchmark Factory,Quest Backup Reporter
Debbie Peabody
Toad Data Point
Gary Piper
Toad Reports Manager
John Pocknell
Toad Solutions
Jeff Podlasek
Toad for DB2
Kuljit Sangha
Toad SC discussions
Michael Sass 
Toad for DB2
Brad Wulf
Toad SC discussions
Richard To
SQL Optimization
  Toad Data Modeler Opens in a new window
Data Modeling
 
  Toad Higher Education
How Hi-Ed Uses Toad
  Real Automated Code Testing for Oracle
Quest Code Tester blog
  中文技术资料库
技术文章
 

Blogs

Toad World blogs are a mix of insightful how-tos from Quest experts as well as their commentary on experiences with new database technologies.  Have some views of your own to share?  Post your comments!  Note:  Comments are restricted to registered Toad World users.

Do you have a topic that you'd like discussed?  We'd love to hear from you.  Send us your idea for a blog topic.


Feb 23

Written by: StevenFeuersteinTW
Friday, February 23, 2007 5:16 PM  RssIcon

Test your code! Debug your code! Trace your code! We all hear about how we should or at least could perform these activities with our programs. And all too often the terms and usages seem to blur, and be confused. In reality, these three activities – test, debug, trace – are all quite different in nature and serve different purposes.

This blog entry offers my perspective on how they differ. I hope you find it useful and I look forward to your comments.

SF

Testing

When you test a program, you run test code that exercises the program. That test code then either tells you whether or not the test succeeded -- or you have to manually go through the results of the test code and deduce for yourself if it worked.

The more automated you can make the testing process the better. Here are the options I know of for automated testing in the world of PL/SQL:

  • Quest Code Tester for Oracle: [disclaimer: I designed this tool, I led the development team, and wrote lots of its backend. It is also sold by my employer, Quest Software.] This tool offers the highest level of test automation in the Oracle tools market. Describe the tests you need to run in a graphical interface, and Quest Code Tester then generates the test code, and runs the test automatically reporting all the results. For more information: http://www.quest.com/code-tester-for-oracle
  •  utPLSQL: this open source framework is modeled after the Extreme Programming unit testing principles. Think "Junit for PL/SQL". I wrote it back in 1999 and 2000 (it has been enhanced further since then) and it has for years been just about your only option for automated unit testing. The problem with utPLSQL is that you still have to write the vast majority of the test code yourself. For more information: http://utplsql.sourceforge.net/
  • PL/Unit: very similar to utPLSQL, PL/Unit predefines a backbone of testing assertion routines which programs may then code to, taking some of the burden off the individual developer. For more information: http://www.apollo-pro.com/help/pl_unit.htm

 

A test identifies a problem in your code, but it usually doesn't give you a whole lot more information than "You passed in 16 and should have gotten back 12. Instead you got 10." You then need to figure out what lines of code are causing that problem. Both tracing and debugging can help you do that.

Tracing

When you trace the execution of your program, you run that program and as it is running, it records or builds a trace of information about what was happening inside the program.

In Oracle PL/SQL, the most common (and also the most crude) type of tracing is a call to DBMS_OUTPUT.PUT_LINE, which sends information to the screen after the program has finished running.

It is not at all rare to come across PL/SQL applications that are littered with calls to DBMS_OUTPUT.PUT_LINE. I generally avoid ever making a direct call to this built-in. For example, in the Quest Code Tester backend I use a tracing utility adapted from the Quest CodeGen Utility qd_runtime package to allow the user to flexibly turn on and off tracing, and write information to the qu_log table. From there, I can extract the data to display on the screen, fill up a file, etc. Here is a simple example from the Quest Code Tester backend:

IF qu_runtime.trace_enabled

 THEN

    qu_runtime.trace ('get_attribute_ex datatype guid'

                     , ret_attr.test_element.data_type_guid                   

                     );

 END IF;

Notice that we call the trace_enabled function to determine if tracing is on before calling the trace subprogram. Qu_runtime.trace will check to see if tracing is enabled but by that time it will have also evaluated the arguments. To achieve the lowest possible runtime overhead, we call trace_enabled, which simply checks the value of a Boolean flag.

We then allow the user to specify when to turn on tracing with a little GUI widget like this:

Conditional compilation, a feature added to PL/SQL in Oracle Database 10g Release 2, can come in very handy with tracing because you can use "CC" to automatically compile the trace logic out of your programs when you don't want it showing up and possibly slowing down the application.

Debugging

Debugging is not the same thing as tracing and it definitely should not be confused with testing. You will generally start a debugging session after your tests have identified a bug. You might have also turned on tracing to get a "dump" of information about the overall flow of the application leading up to the bug.

With this "raw data" (specific test case failure information and trace data), you then need to find the specific lines of code that are causing the bug, and also figure how to change those lines of code to fix the bug. Given the maturity of the PL/SQL IDE (integrated development environment) market, most serious editors including a visual source code debugger.

For example, in Toad, you click in the "gutter" of the editor next to the line on which you want execution to "break" or pause. You start up your program and it runs to the breakpoint. You can then examine the values of variables, change values (in some debuggers), then step through the code, line by line, examining the program flow and how data structures are affected.

PL/SQL source code debuggers are incredibly useful and some are very powerful flexible implementations. Make them a part of your toolset when searching out the causes of bugs in your code!

Summary

To sum it all up, when thinking about identifying and fixing bugs in your code, keep in mind the differences between testing, tracing and debugging:

  • Test your code to identify bugs that occur under a certain set of circumstances (a "test case" with specific inputs to arguments in the program).
  • Turn on tracing and obtain a usually substantial amount of "raw data" about what the program did as it ran.
  • Use your debugger to isolate the specific lines of code that caused the bug (and correspond to the flow indicated by the trace data).

Then use your IDE to fix the bug, and start the cycle all over again!

Search Blog Entries
 
Blog Archives
 
Archive
<May 2013>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Monthly
May, 2013 (15)
April, 2013 (13)
March, 2013 (10)
February, 2013 (5)
January, 2013 (7)
December, 2012 (6)
November, 2012 (10)
October, 2012 (8)
September, 2012 (6)
August, 2012 (8)
July, 2012 (8)
June, 2012 (12)
May, 2012 (21)
April, 2012 (10)
March, 2012 (16)
February, 2012 (19)
January, 2012 (20)
December, 2011 (19)
November, 2011 (14)
October, 2011 (12)
September, 2011 (17)
August, 2011 (15)
July, 2011 (16)
June, 2011 (13)
May, 2011 (15)
April, 2011 (8)
March, 2011 (21)
February, 2011 (17)
January, 2011 (16)
December, 2010 (13)
November, 2010 (13)
October, 2010 (7)
September, 2010 (15)
August, 2010 (11)
July, 2010 (13)
June, 2010 (12)
May, 2010 (14)
April, 2010 (12)
March, 2010 (13)
February, 2010 (12)
January, 2010 (7)
December, 2009 (10)
November, 2009 (12)
October, 2009 (15)
September, 2009 (18)
August, 2009 (13)
July, 2009 (23)
June, 2009 (14)
May, 2009 (17)
April, 2009 (7)
March, 2009 (14)
February, 2009 (7)
January, 2009 (12)
December, 2008 (7)
November, 2008 (11)
October, 2008 (19)
September, 2008 (14)
August, 2008 (11)
July, 2008 (14)
June, 2008 (19)
May, 2008 (12)
April, 2008 (18)
March, 2008 (13)
February, 2008 (8)
January, 2008 (7)
December, 2007 (5)
November, 2007 (8)
October, 2007 (13)
September, 2007 (13)
August, 2007 (16)
July, 2007 (11)
June, 2007 (6)
May, 2007 (5)
April, 2007 (5)
March, 2007 (8)
February, 2007 (6)
January, 2007 (6)
December, 2006 (5)
November, 2006 (8)
October, 2006 (4)
August, 2006 (3)