<< Chapter < Page Chapter >> Page >

Testing

There are many ways to test your code. The most formal way is to use JUnit testing facilities, which is covered in a separate module: Unit Testing with JUnit in DrJava . For simple tests, you can test your code by directly interacting with it in the Interactions pane.

Debugging

To debug a program in DrJava, first put DrJava into Debugging Mode by setting the check box under the Debugger on the main menu. This will enable all the other debugging features. When debugging mode is active, the debugging pane will appear near the bottom of the DrJava window. This pane contains the Watch window and tabs that show the current Stack and Threads status. The debugging pane also has buttons for Resume debugging, Step Into , Step Over and Step Out . These features are described in detail below.

The basic technique for debugging is to set breakpoints on lines of code that are of interest/problematic and then to either step slowly through the code execution from that point and/or to examine the values of various variables.

Breakpoints : Under debugging mode, DrJava will stop the execution of a program whenever a breakpoint is encountered. Execution stops before the breakpoints line of code is run. To set or clear a breakpoint, place the cursor on the desired line of code and either use the Debugger/Toggle Breakpoint on Current Line or by simply pressing Ctrl-B or by right-clicking the desired line and selecting Toggle Breakpoint . Note that it only makes sense to put a breakpoint on a line of code that actually executes, which excludes

  • Blank lines
  • Comments
  • Method signature lines
  • Lines with a single curly brace on them.
  • Field/attribute declarations that have no initialization code.

To clear a breakpoint , follow the same procedure used to set the breakpoint.

Whenever the program execution is stopped on a line of code, the Interactions pane can be used to examine the value of any variable that is in scope or even to execute methods on those variables (if they are objects). You can even set the values of any available variables by assigning a new value to them. This is useful if they have the wrong value for some reason and you want to check if the rest of your code will run properly if the correct value is present.

Clear All Breakpoints : Clicking on Debugger/Clear All Breakpoints will clear all breakpoints that have been set in your program.

Clicking on Debugger/Breakpoints or pressing Ctrl+Shift+B will bring up a tabbed pane at the bottom of the DrJava window that enables you to conveniently examine, navigate to, delete, or disble (without deleting) all of the breakpoints in your program.

Step Into : When execution has stopped on a line of code, clicking on the Step Into button in the debugging pane or selecting the menu item Debugger/Step Into or pressing F12 will cause the current line of code (highlighted in blue) to be executed. If the current line of code involves the invocation of a method, then the current line of code will be advanced into the first method to be called, as per Java's order of execution rules. If the current line of code is the last line in a method, the current line of code will become the next executable line of code in the method that called the current method. Note that if the caller's line of code involved multiple method calls, then the current line of code will return to that line of code in the caller and then execution will advance into the next method to be called, or if the current method was the last method to be called, the current line of code will be the next line of code in the caller.

Step Over : When execution has stopped on a line of code, clicking on the Step Over button in the debugging pane or selecting the menu item Debugger/Step Over or pressing F11 will cause the current line of code to be executed. This is very similar to Step Into, but if the the execution will not stop inside of any methods called in the current line of code. Thus the new current line of code will always be in the same method, unless the executed line was the last line in the method, upon which execution will stop in the calling method as usual. This feature is very useful when you are confident that the methods being called work properly and you are not interested in their detailed execution.

Step Out : When execution has stopped on a line of code, clicking on the Step Out button in the debugging pane or selecting the menu item Debugger/Step Out or pressing Shift+F12 will cause the execution to resume until the current method exits. Excution will stop at the next executable line in the calling method . This is very useful to quickly exit a method whose detailed execution no longer interests you (for instance, if you accidentally stepped into a method that you wanted to step over).

Resume Debugging : When execution has stopped on a line of code, clicking on the Resume button in the debugging pane or selecting the menu item Debugger/Resume Debugging or pressing F7 will cause the program execution to resume and continue until the next breakpoint is encountered. This is useful when you are no longer interested in the detailed execution of the code until the next breakpoint.

Watches : Watches are used when you want to continuously monitor the value of a particular variable. Simply type the name of the variable or field into the Watch pane and when code execution has paused, if that variable name is in scope, its value will be displayed.

Stack : The stack contains an ordered list of all methods with pending operations at any given point of a program's execution. That is, when the program execution has stopped at a particular line of code, the stack contains the method that line of code is in, the method that called that method, the method that called that method, etc. In DrJava, the Stack tab will show the stack with the current method at the top and the calling method below it. Looking at the stack is very useful for determining where in your program you actually are, as often a method is called from locations that are unintended or one discovers that a method is not being called from where you wish it to be called.

Threads : A Java program run on many simultaneous execution paths or "threads", each performing different tasks necessary for the total operation of a Java application. A simple program written by a programmer may have a single thread that runs the code written by that programmer, but may also have many other threads performing such tasks as managing the graphical user interface (" GUI ") or managing the memory allocated to the program. It is also possible for a programmer to write code that utilizes multiple threads of execution to accomplish the desired goals. The Threads tab is most useful for debugging these multi-threaded programs by enabling the developer to better understand which threads are accessing which objects.

Questions & Answers

what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
What are the treatment for autism?
Magret Reply
hello. autism is a umbrella term. autistic kids have different disorder overlapping. for example. a kid may show symptoms of ADHD and also learning disabilities. before treatment please make sure the kid doesn't have physical disabilities like hearing..vision..speech problem. sometimes these
Jharna
continue.. sometimes due to these physical problems..the diagnosis may be misdiagnosed. treatment for autism. well it depends on the severity. since autistic kids have problems in communicating and adopting to the environment.. it's best to expose the child in situations where the child
Jharna
child interact with other kids under doc supervision. play therapy. speech therapy. Engaging in different activities that activate most parts of the brain.. like drawing..painting. matching color board game. string and beads game. the more you interact with the child the more effective
Jharna
results you'll get.. please consult a therapist to know what suits best on your child. and last as a parent. I know sometimes it's overwhelming to guide a special kid. but trust the process and be strong and patient as a parent.
Jharna
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply
Practice Key Terms 3

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Principles of object-oriented programming. OpenStax CNX. May 10, 2013 Download for free at http://legacy.cnx.org/content/col10213/1.37
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Principles of object-oriented programming' conversation and receive update notifications?

Ask