6) debugging and testing


Published on

Published in: Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Main Point: IBM is continuing to evolve and enhance the value that we bring to companies by building on the SOA announcements we made last fall…today we are going to talk to you about how a Business Centric Perspective to SOA is necessary to drive innovation that matters* As you know, SOA is one of IBM’s long term strategies to enable innovation that matters. IBM will continue to deliver SOA centric offerings. But we also want you to know that IBM’s view of SOA is business centric. and we’ll talk about this important concept. Further, we’ll discuss ways to get started through existing parts of your business (people process, information). Additionally, we’ll show how reuse and connectivity is critical to support the business centric approach. We’ll then give you detail on how the specific entry points are accelerated by SOA Foundation products and the business insight these products provide. Lastly, we’ll discuss an important part of the story called SOA Governance to ensure we’re aligning the business with IT.
  • Notes:   Instructor notes: Purpose -- Informational slide giving the panorama of possibilities. Details -- Additional information -- Don't be tempted to explain each bullet! It would be sufficient to spend just a few moments here, long enough to show that the tool has wide capabilities for debugging. Mention that it is the first category that is the focus of the next 45 minutes, but that the principles covered will apply very largely to the other options. Transition statement -- Next: Debug View
  • Statement filtering is a preference, controlled via Window > Preferences > Java > Debug > Step Filtering
  • Notes: Not to be confused with Step Filters, which are used during step-by-step debugging of J2EE and Web Objects, and are discussed later in this course. Step Filters are specified in Window > Preferences > Run/Debug > Java and Mixed Language Debug > Step Filters . Instructor notes: Purpose -- Details -- Additional information -- Step filter: Filters that can be applied to normal debugging (step into/over/return). Step-by-step filtering: Filters applied to Web objects loaded by the server.   Make sure that students understand this distinction by the time you have presented slide 18 - there will be a checkpoint question on this! Transition statement -- Next: Configuring Step Filters
  • Notes: Use the Step Filters with Shift-F5 also. Most filters blank out entire packages. The selected filter for a specific class. Filters are applied top-down, and the first match will be utilized. You can change the Step Filters by right-clicking in the Debug View and selecting Edit Step Filters . Note: Synthetic methods are methods that were created by the compiler and do not exist in the source code. Instructor notes: Purpose -- Details -- Additional information -- Transition statement -- Next: Debugging JavaServer Pages
  • Notes: Java exception breakpoints suspend execution at the point where the exception is thrown. Execution can be suspended when an exception is uncaught, caught, or both. Most of the toolbar icons on the Breakpoints view are self explanatory. The Show Breakpoints Supported by Selected Target button deserves an explanation: Normally a list of all breakpoints (for all debug sessions) appears in the Breakpoints view, unless you use the filter by debug target action. To filter out breakpoints that are not related to the current debug session, click the Breakpoints view Show Breakpoints Supported by Selected Target button, or right-click in the view and enable the Show Supported Breakpoints pop-up menu item (this menu item is enabled when there is a check mark to the left of it). Instructor notes: Purpose -- Details -- Additional information -- The Java Exception breakpoint is the important teach point of this slide (make sure to go into Rational Application Developer to show this). Ask students why Exceptions should be singled out in this way. ANSWER: There may be no provision for some particular Exception, and therefore nowhere to put a breakpoint. It can be really useful to have execution suspended at the instant of the Exception being thrown in order to examine variable values. Transition statement -- Next: Adding a Breakpoint into a Web Application
  • Exceptions are a Java mechanism for handling errors, both expected and unexpected. We will talk about them at length in a later lecture.
  • Notes: Instructor notes: Purpose -- Details -- Additional information -- Make sure that students understand that you would never want to have breakpoints lined up in this fashion in a debug session! This would be a good place to ask the question, `How many breakpoints do you need?'. ANSWER: There are a lot of different answers, of course. Some points to make are: It may be faster to step over lines to get to the code you want to examine rather than have two breakpoints separated by (say) 8 lines of code; Don't hesitate to move a breakpoint to a better location (closer to where a problem is occurring), but don't forget to remove or disable the original breakpoint. Transition statement -- Next: Configuring Breakpoint Properties
  • Notes: The hit count must be a single positive integer. The condition can be complex, and might suspend execution several times. Any expression is valid as long as it evaluates to a boolean: Name.equals(employee.getName()) Double.compare(Math.random(), 0.5 == 1) thisTemperature != previousTemperature Execution suspends either when the condition is true or when the value changes. Instructor notes: Purpose -- Details -- Additional information -- The hit counter and conditions can be used together. Don't get into explanations about threads and VMs. Transition statement -- Next: The Variables View
  • Notes: A visible variable is one that has been initialized. Notice that in the above code, execution is suspended on the line where resultString is created. The variable is not yet visible, so it is not in the Variables view. Stepping one line further will add it. Instructor notes: Purpose -- Details -- Additional information -- The lower half of this view is called the details pane. It will be seen in the next slide that it can divide the view horizontally or vertically, or hidden. Transition statement -- Next: Viewing and Changing Variables During Debugging
  • Notes: Instructor notes: Purpose -- Details -- Additional information -- Java primitives are not mentioned. If any student asks, Here is the relevant dialog: // Screen capture of the “Primitive Type Display Options” dialog deleted Transition statement -- Next: Data in the Expressions View
  • Notes: You can examine the values in this window. The window cannot be moved, and will only close when you either click in the editor or press Ctrl-Shift-i a second time. Instructor notes: Purpose -- Details -- Additional information -- Transition statement -- Next: Step Filtering
  • Notes: The Java development environment contributes a scrapbook facility that can be used to experiment and evaluate Java expressions (code snippets). Snippets are edited and evaluated in the Scrapbook page editor. In the editor you can select a code snippet, evaluate it, and display the result as a string, or you can show the result object in the debugger's inspector. The scrapbook is a useful feature to perform microscopic preliminary testing during development. Instructor notes: Purpose -- Details -- Additional information -- Transition statement --
  • Notes:   Instructor notes: Purpose -- Details -- Additional information -- Transition statement --
  • Notes: When using WebSphere Application Server, you can save the generated .java files compiled from JSP files. Open the Deployment Descriptor for the Web application Click the Extensions tab In the JSP Attributes area, click Add to add the following key value pairs. name=keepgenerated value=true name=scratchdir value=C:/temp The generated files are stored in the location specified by the scratchdir property. Server-side JavaScript can be used as the scripting language in a JSP. The JavaScript debug adapter enables you to diagnose errors in JavaScript that is running locally or remotely on a WebSphere Application Server With the debug adapter, you can control the execution of your JavaScript by setting line breakpoints, stepping through your code, and examining the contents of variables Once you have launched a debug session you will need to do the following: Access the Web object by entering its URL in a browser. Use step-by-step debugging. Upon entering the Web object, step until a JavaScript stack is reached and the editor displays a JavaScript block, or set a breakpoint in your JavaScript and run until it is reached Some points to note when debugging JSPs: Step-by-step debug will not work well for JSPs that do not contain any executable code. Execution will halt at the top of the JSP, however there is nothing to "step" to. Run to line is not supported in JSPs. Setting JSP breakpoints may be slow. Allow extra time for the debugger to initialize if there are many JSP breakpoints. Breakpoint properties (such as hit count, condition, selected thread, and VM suspend policy ) are not supported for JSP breakpoints. When you add a condition, the debugger will not stop at that breakpoint. You may need to publish the application to force the application server to pick up the breakpoints. Instructor notes: Purpose -- Details -- Additional information -- Draw students' attention to the points in the notes. They are all important. You might like to include them in the live presentation as well. Transition statement -- Next: What is Remote Debugging?
  • RUP Rational Unified Process, Developer Tab , Designer > Concepts > J2EE to RUP Mapping Rational Unified Process, Developer Tab , Designer > Enterprise JavaBean (EJB) Design > Guideline s > Designing Enterprise JavaBeans (EJBs) Web Resources http://www-130.ibm.com/developerworks/ http://w3.ams1.ibm.com/services/ams/competency/ams/tools_support/rational/learn_about/ams_rational_advanced_learning.html EJB Best Practices: Entity Bean Protection: http://www-106.ibm.com/developerworks/java/library/j-ejb1008.html Literature Enterprise Java Programming with IBM® WebSphere®, Second Edition By Kyle Brown, Gary Craig, Greg Hester, Russell Stinehour, W. David Pitt, Mark Weitzel, Jim Amsden, Peter M. Jakab, Daniel Berg Additional Courses Introduction to Web Services - http://w3-3.ibm.com/education/CourseDescriptionServlet.wss?city=&state=&countrycode=&coursecode=XM371&courseDescrLanguageId=1 WebSphere Training and Technical enablement: http://www-128.ibm.com/developerworks/websphere/education/enablement/curriculum/cur_webtoolside.html Review resources with students and answer questions.
  • Self explanatory
  • 6) debugging and testing

    1. 1. Vikas Manoria IT Specialist – IBM Academic Initiative [email_address] Section - 6) Debugging and Testing
    2. 2. Section 6 - Debugging and Testing (18%) <ul><li>Manage breakpoints </li></ul><ul><li>Step through and examine Java code </li></ul><ul><li>View variables and execute, display and inspect expressions </li></ul><ul><li>Create and run code in Scrapbook page </li></ul><ul><li>Perform JSP debugging </li></ul><ul><li>Use step-by-step debugging </li></ul><ul><li>Locate and view WebSphere application server logs </li></ul><ul><li>Perform unit testing using JUnit </li></ul>
    3. 3. Debug Tooling <ul><li>Rational Application Developer supports debugging in several programming languages and environments </li></ul><ul><ul><li>Java </li></ul></ul><ul><ul><li>Active Script (client-side JavaScript or Visual Basic script) </li></ul></ul><ul><ul><li>SQL Stored Procedures, SQLJ </li></ul></ul><ul><ul><li>EGL, XSL Transformations </li></ul></ul><ul><ul><li>Mixed language </li></ul></ul><ul><ul><li>WebSphere Application Server environment (includes servlets, JSPs, and EJBs) </li></ul></ul><ul><li>It is opened under the following conditions </li></ul><ul><ul><li>Execution hits a breakpoint that you inserted </li></ul></ul><ul><ul><li>An uncaught exception occurs </li></ul></ul><ul><ul><li>You select the debug button ( ) on any tool bar </li></ul></ul>
    4. 4. Debugger Capabilities <ul><li>Modify </li></ul><ul><ul><li>Code while in the debugger </li></ul></ul><ul><ul><li>Data values while stepping through code </li></ul></ul><ul><li>While in the debugger </li></ul><ul><ul><li>Set breakpoints </li></ul></ul><ul><ul><li>No unnecessary editions are created </li></ul></ul><ul><ul><li>Multithreading support </li></ul></ul><ul><li>To debug your code you do not have to </li></ul><ul><ul><li>Recompile in the Java editor, or </li></ul></ul><ul><ul><li>Add source code, such as System.out.println(...) into the code </li></ul></ul>
    5. 5. Debugger Perspective <ul><li>Debugger can </li></ul><ul><li>be used to inspect, </li></ul><ul><li>change, and step </li></ul><ul><li>through code </li></ul><ul><li>The source can </li></ul><ul><li>be changed,saved, </li></ul><ul><li>and resumed from </li></ul><ul><li>within the debugger </li></ul>Source Execution Stack Frame Variables Pane
    6. 6. Stack Frames <ul><li>The debugger displays lists of stack frames before exception or breakpoint occur </li></ul><ul><li>Stack frames </li></ul><ul><ul><li>Correspond to a called method </li></ul></ul><ul><ul><li>Are in reverse chronological order -- Last one executed is first </li></ul></ul><ul><li>Any stack frame can be selected and “dropped to.” The code is then </li></ul><ul><li>re-executed </li></ul><ul><ul><li>Choose a frame and </li></ul></ul><ul><ul><li>select the Relaunch </li></ul></ul><ul><ul><li>option defined in the </li></ul></ul><ul><ul><li>pop-up </li></ul></ul><ul><ul><li>Variable values are </li></ul></ul><ul><ul><li>not reset when a </li></ul></ul><ul><ul><li>stack frame is </li></ul></ul><ul><ul><li>dropped </li></ul></ul>
    7. 7. <ul><li>Resume - Continues execution until breakpoint or thread ends </li></ul><ul><li>Suspend - Interrupts a running thread </li></ul><ul><li>Terminate - Ends the execution of the selected thread </li></ul><ul><li>Step Into – Steps into a method call and executes the first line of code in that method </li></ul><ul><li>Step Over - Executes the next line of code in the current method </li></ul><ul><li>Step Return - Continues execution until the end of the current method (until a return) </li></ul><ul><li>Step with Filters – Continues execution until the next line of code which is not filtered out </li></ul>Stepping Through Code Commands 1 2 3 4 5 6 7
    8. 8. Step Filtering: Java <ul><li>Used to avoid stepping into specified packages and classes while debugging </li></ul><ul><li>Affects Step Into and Step Return while debugging </li></ul><ul><ul><li>Specified packages and classes will be stepped over </li></ul></ul><ul><li>Is set in the Preferences dialog </li></ul><ul><ul><li>Window > Preferences > Java > Debug > Step Filtering </li></ul></ul><ul><li>They are independent of the Step Filters, which are used during step-by-step debugging of J2EE and Web Objects </li></ul>
    9. 9. Configuring Step Filtering: Java <ul><li>Toggle the Use Step Filters button in the Debug view toolbar </li></ul><ul><ul><li>Each of the step actions ( over, into, return ) will then apply to the set of step filters which are defined in the preferences </li></ul></ul>
    10. 10. Breakpoints View <ul><li>Lists all the breakpoints you have set in the workbench, as well as Java Exception breakpoints </li></ul><ul><ul><li>Double-click a breakpoint to display its location </li></ul></ul><ul><ul><li>Enable or disable breakpoints, add or delete them </li></ul></ul>Add Java Exception breakpoint Skip all breakpoints Show Breakpoints Supported by Selected Target Remove All Breakpoints Remove Selected Breakpoints
    11. 11. Exception Breakpoints <ul><li>Exception can be enabled as breakpoints in the Breakpoint view </li></ul><ul><ul><li>Execution will suspend wherever the exception is raised </li></ul></ul><ul><ul><li>Can specify “caught”, “uncaught” or both. </li></ul></ul>
    12. 12. Where Are You Allowed to Enter Breakpoints? <ul><li>Breakpoints are set on an executable line of a program </li></ul><ul><li>If you try to add a breakpoint on a line where there is no executable code, Rational Application Developer will either: </li></ul><ul><ul><li>Add one at the next possible location (in Java code) </li></ul></ul><ul><ul><li>Display a red error message in the status bar </li></ul></ul>
    13. 13. Configuring Breakpoint Properties <ul><li>You can enable or disable breakpoints </li></ul><ul><ul><li>Newly added breakpoints are enabled by default </li></ul></ul><ul><li>Hit count breakpoints </li></ul><ul><ul><li>The thread execution suspends when the breakpoint is hit for the nth time </li></ul></ul><ul><ul><li>The breakpoint is disabled until either it is re-enabled or its hit count is changed </li></ul></ul><ul><li>Conditional breakpoints </li></ul><ul><ul><li>Must evaluate to a boolean </li></ul></ul><ul><ul><li>Only invoked if condition </li></ul></ul><ul><ul><li>evaluates to true or value </li></ul></ul><ul><ul><li>changes </li></ul></ul><ul><li>Filtering: filter per thread </li></ul><ul><li>Method breakpoints suspend </li></ul><ul><li>method Entry or Exit </li></ul>
    14. 14. The Variables View <ul><li>Examine the contents of variables when a thread suspends </li></ul><ul><ul><li>Top stack frame of the thread is automatically selected </li></ul></ul><ul><ul><li>Visible variables of the selected stack frame are displayed </li></ul></ul>
    15. 15. Viewing and Changing Variables During Debugging <ul><li>Change a value by selecting Change Variable Value from the context pop-up menu on a particular variable </li></ul><ul><li>Show type names adds the type before variable identifiers </li></ul><ul><li>Other options can be set using the toolbar menu </li></ul><ul><ul><li>For example: Detail Pane > the number of lines shown </li></ul></ul>1 2
    16. 16. Data in the Expressions View <ul><li>In the Expressions view, you can inspect data from a scrapbook page or a stack frame of a suspended thread </li></ul><ul><li>The view is not initially open in the debug perspective </li></ul><ul><ul><li>It opens automatically when an item is added to the view </li></ul></ul><ul><li>To inspect data in this view, select a variable in the code and press Ctrl-Shift-i twice </li></ul><ul><ul><li>The first time opens a window with the expression </li></ul></ul><ul><ul><li>The second time moves the contents of the window to the Expressions view </li></ul></ul>
    17. 17. Run Sample Code with Scrapbook Pages <ul><li>Scrapbook pages allow you to evaluate and test a small section of code without creating an entire class. </li></ul><ul><ul><li>To evaluate a code fragment in the scrapbook page, highlight an expression and select Display from the pop-up menu. </li></ul></ul><ul><ul><li>Add other classes or packages using Set Imports . </li></ul></ul>
    18. 18. Create a New Java Scrapbook Page <ul><li>Start the New Java Scrapbook wizard. </li></ul><ul><ul><li>In the Java perspective, select File > New > Other . </li></ul></ul><ul><ul><li>Expand Java -> Java Run/Debug and select Scrapbook Page. </li></ul></ul><ul><ul><li>Click Next . </li></ul></ul><ul><li>Specify the name and location for the new Java scrapbook page. </li></ul><ul><ul><li>Specify a location for the scrapbook page. </li></ul></ul><ul><ul><li>Choose a name for the scrapbook page. </li></ul></ul><ul><ul><li>Click Finish . </li></ul></ul>
    19. 19. Debugging JavaServer Pages <ul><li>You cannot set breakpoints on lines that only contain HTML </li></ul><ul><li>You can set breakpoints in: </li></ul><ul><ul><li>Java code </li></ul></ul><ul><ul><li>JSP, Struts, and JSF tags </li></ul></ul><ul><ul><li>JavaScript </li></ul></ul><ul><li>Select the JSP file and click Debug As > Debug on Server from the context pop-up menu </li></ul><ul><ul><li>The server automatically starts in debug mode </li></ul></ul><ul><ul><li>The debugger stops at the breakpoint and displays the JSP </li></ul></ul><ul><li>Step through the JSP file, examine and change variable values </li></ul><ul><li>Refresh the JSP in the Web browser to view changes made while debugging </li></ul><ul><ul><li>The state of the application is not lost, and the server recognizes your changes </li></ul></ul><ul><ul><li>You do not need to republish to see JSP changes </li></ul></ul>
    20. 20. Lab <ul><li>Debug Java application </li></ul><ul><li>Breakpoints and debug views </li></ul><ul><li>Step through code </li></ul><ul><li>Variables and examine views </li></ul><ul><li>Debug Web application </li></ul><ul><li>Start server in debug mode </li></ul><ul><li>Step-by-step debugging </li></ul><ul><li>Create a Test project </li></ul><ul><li>Create JUnit test cases </li></ul><ul><li>Run and analyse test cases </li></ul>
    21. 21. Japanese Hebrew Thank You English Merci French Russian Danke German Grazie Italian Gracias Spanish Obrigado Portuguese Arabic Simplified Chinese Traditional Chinese Thai Korean