Lab 5-1: Debugging an Application

Lab 5-1: Debugging an Application

In this lab, you will open a small application that contains syntax, run-time, and logical errors. You will correct syntax errors, design a test plan to identify and correct run-time and logical errors in two methods, and use the Visual Studio debugging tools to monitor program execution. The solution to this lab is available on the Supplemental Course Materials CD-ROM in the \Labs\Ch05\Lab 5-1\Solution folder.

Before You Begin

There are no prerequisites to starting this lab.

Estimated lesson time: 30 minutes

Exercise 5-1.1: Identifying Syntax Errors

In this exercise, you will use Visual Studio .NET to identify and correct syntax errors in the sample project. To open the Lab 5-1 project:

  1. Start Visual Studio.

  2. From the File menu, choose Open, and then Project. The Open Project dialog box appears.

  3. Browse to the \Labs\Ch05\Lab 5-1\Partial folder and choose either VB or C Sharp, as appropriate. Click Open to open the solution.

To identify and correct syntax errors

  1. From the Build menu, click Build Solution. Syntax errors appear in the Task List window, as shown in Figures 5.3 and 5.4.

  2. figure 5-3 the task list window in visual basic .net

    Figure 5-3. The Task List window in Visual Basic .NET

    figure 5-4 the task list window in visual c#

    Figure 5-4. The Task List window in Visual C#

  3. For Visual Basic .NET, double-click the error that reads Select Case must end with a matching End Select . You are taken to the end of the Select Case block. Examine the code and correct the error by correcting the syntax in the End Select line. Note that only two errors are displayed in the Task List window.

    For Visual C#, double-click the first error that reads } expected . You are taken to the end of the operation handler. Carefully examine each pair of curly braces to determine which one is missing its partner. Correct the error by adding the appropriate brace to the end of the first switch statement.

  4. For Visual C# only, from the Build menu, choose Build Solution to reassess your code for errors. Note that two additional errors are found.

  5. Double-click the first error in the Task List. You are taken to an error that cannot find a member named CurretOperation. Change this statement to read CurrentOperation to correct the error.

  6. Double-click the final error in the Task List. Correct the spelling of Regiter2 to correct the error.

  7. From the Build menu, choose Build Solution. Note that no further errors are discovered.

Exercise 5-1.2: Identifying Run-Time Errors

Now that you have rid your code of syntax errors, you can tackle the run-time errors and logical errors. In the next two sections, you will test two methods, each of which contains one or more errors. You should examine each method to develop a test plan for that method. Every possible data path should be tested with a variety of normal and abnormal input. Continue your test plan until you feel confident that all errors have been found. Then, check your work against the solution in \Labs\Ch05\Lab 5-1\Solution.

To identify and correct a run-time error

  1. Locate the NumberHandler method. This is a fairly simple method with minimal data path branching. This method builds a string of numbers as buttons 1 through 9 are pressed on the calculator face.

  2. Develop a test plan for this method. Your test plan should explore all possible data branches and test the method with a variety of input and application variable values. Determine the expected results of each test case in advance. Table 5.4 demonstrates some of the test cases you might use.

    Table 5-4. Test Cases for the NumberHandler Method

    Button Pressed

    Value of LabelDisplay.Text

    Value of CurrentNumberString

    Value of CurrentNumberString expected

    1

    0

    1

    4

    44

    44

    444

    9

    1266345578456

    1266345578456

    12663455784569

    9

    -3446.222231

    -3446.222231

    -3446.2222319

    3

    6

    6

    63

  3. Execute your tests. Use the Locals, Autos, and Watch windows to observe the values of variables as the program executes. Use the Immediate window to assign values to variables. You can use Set Next Statement to rerun code multiple times.

  4. Log your results and correct any run-time errors you find.

Exercise 5-1.3: Identifying Logical Errors

Logical errors are the most difficult types of errors to identify. It frequently takes repeated testing to observe a problem and additional testing to identify the source of the error. In the next section, you will identify a logical error in another method of this application.

To identify and correct a logical error

  1. Locate the method named EqualsHandler. This method handles operations for the calculator when the equals (=) button is pressed. The number contained by the variable Register1 is added to, subtracted from, multiplied by, or divided into the number contained by Register2, and the value of that operation is assigned to Result. The user interface is then updated.

  2. Execute the test plan shown in Table 5.5. Although incomplete, the plan does test every logical path through the method and should be sufficient to find a logical error. Note that boundary analysis and in-depth testing has been omitted for the purpose of brevity.

    Table 5-5. Test Cases for the EqualsHandler Method

    Current Operation

    Register1

    Register2

    Expected Value of Result

    Operation.Plus

    442

    5789

    6231

    Operation.Minus

    400000

    222222

    177778

    Operation.Multiply

    23

    12

    276

    Operation.Divide

    3345

    34

    98.3823529411765

  3. Diagnose and resolve any logical errors you encounter.



MCAD(s)MCSD Self-Paced Training Kit(c) Developing Windows-Based Applications With Microsoft Visual Basic. Net a[.  .. ]0-316
MCAD(s)MCSD Self-Paced Training Kit(c) Developing Windows-Based Applications With Microsoft Visual Basic. Net a[. .. ]0-316
ISBN: 735619263
EAN: N/A
Year: 2003
Pages: 110

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