• Save
6) debugging and testing
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
3,073
On Slideshare
3,073
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    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

Transcript

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