Building and debugging application

Assignment Help Software Engineering
Reference no: EM132865251

ITAP2008 Software Testing - Victorian Institute of Technology

Lab 7

Creating a project and supporting unit tests

During this lab session, you'll go through the process of creating a new project, as well as some supporting unit tests.

Task 1: Creating a new class

In this task, you'll create a basic class Calculator.cs.
1 Open Visual Studio 2013.
2 From the main menu, select File | New | Project.
3 In the New Project dialog, select the Visual C# | Windows Desktop and Console Application template (As shown in Figure 1). Type "Calculator" as the Name (This will be the namespace) and click OK.

4 In Solution Explorer, Right-click the Program.cs and select Rename. Change the name to "MyCalculator.cs".

5 When asked to update the name of the class itself, click Yes.

6 Add the following C# code for the class MyCalculator.cs.

C#?
static void Main(string[] args)
{
int a = 5, b = 8, c = 233; int d = a + c - b; Console.WriteLine(d);
}

Note: For the purposes of this lab, all operations will be performed using the int value type. In the real world, calculators would be expected to scale to a much greater level of precision. However, the requirements have been relaxed here to focus on the debugging.

Task 2: Adding a Breakpoint

In this task, you'll add a breakpoint to the class and the code will stop execution from that breakpoint. Then you can manually run the code using key F11

There are different ways you can add break points.

1. First move the cursor to the line you need to add breakpoint. And from the menu select add Breakpoint.

2. Place a breakpoint by clicking in the left gutter

Once you added the breakpoint your IDE should now look something as in the figure 3.

Task 3: Building and Debugging Application

1. Build application, by clicking the Build |Build Solution

2. Now select Debug | Start Debugging.

3. Now select Debug | Start Debugging.

4. The program will stop at the breakpoint. Now use F11 to go forward in the code (line by line). You will be able to traverse line by line in the program. At the same time, you can check the attribute values and check the problems with assignment of the values.

Task 4: Understanding Debug Menu

Figure 12 shows the Debug menu with Visual Studio 2013. Using this user can start debugging process

by adding breakpoints. And stop debugging. Can step into codes and go through one line by line to examine the code.

Task 5: Debugging a Small Code

1. Create a new C# class with the name CalcFactorial. New Project | Windows Desktop | Console

Application

2. Add following code between class brackets. C#
static void Main(string[] args)
{
Console.WriteLine("Enter a Number to find Factorial"); int number = Convert.ToInt32(Console.ReadLine());

int fact = getFactorial(number);
Console.WriteLine("{0} Factorial is {1}", number, fact);
}

// New method getFactorial
public static int getFactorial(int num) { if (num == 1)
{
return 1;
}

return num * getFactorial(num-1);

}

3. Add breakpoint to the code on the keyboard input assignment statement. (Use enters the number here and assign the value on the integer type number variable.)

4. Build and debug the console application. Debug | Start Debugging

5. The application starts for the input.

6. User enters the value. (Note: You can enter any integer value.)

7. Now press F11. And move forward in the code. Note the yellow arrow. The yellow arrow shows that how F11 moves through you the code. It has moved to the next line and highlighted in

yellow. Same time note that the Autos section in the left hand side bottom input 5 has assigned on the variable number (this shows in red color).

8. Press F11. Observe how the yellow arrow moves.

9. The pointer checks the if condition.

10. Move the cursor onto the if statement. Then it shows whether the values assigned satisfy the condition or not. (Note: in the following example the statement become false due to not meeting the condition.)

11. Next F11 press.

12. The function getFactorial() is a recursive function and called recursively. Next f11 press will call the function again.

13. Now notice that the value for num variable is 4. Still does not meet the condition criteria.

14. The third call for function getFactorial(). The function will be recursively called and you will be able to see how the pointer moves and how conditions will be met.

15. Meeting if condition. The recursive call will deduct num variable and now numis 1 and enters to the if condition. See the display. It says now the condition is true with num variable.

16. Returning 1. Going into if condition and returning 1.

17. For the next F11 the pointer will exit from the function getFactorial and returns to the main method. Then executes Console.WriteLine statement and prints output on the console.

18. Printing the output on the console.

Task 5: Practice - How loops works - Understand by debugging

1. Create new console application and add following code segment to that.

C#

class Stars
{
static void Main(string[] args)
{
for (int i = 0; i <= 3; i++ )
{
for (int j = 0; j <= 3; j++)
{
Console.Write("*");
}
//Console.WriteLine();

}
Console.ReadLine();
}
2. Add breakpoint to the outer for loop as showing in the Figure 30.

3. Run the debugging process and see how for loops works and prints the stars.

Task 4: Exercises

1. Use following C# code segment.
o Expected output = 288
o Actual output = 219

2. Debug the code to locate the error and fix the error.

C#
class Stars
{
static void Main(string[] args)
{

int a = 48; int b = 2; int c = 9; int d = 3;

int f = a/b*9+3;
Console.WriteLine("The answer is {0}",f);

Console.ReadLine();
}
}

Note: All figures are attached in below file.

Attachment:- Lab Tutorial Lesson 7.rar

Reference no: EM132865251

Questions Cloud

Discuss different ways immigrants to america : Discuss different ways immigrants to America from THREE (3) different countries/regions of the world have used their narrative voices as a tool for activism.
What is a spint in agile environment : What is a spint in agile environment - When the customer in an Agile project provides feedback indicating that a piece of functionality was not implemented
What is the amount of the lease liability on January : Assuming that this is classified as an operating lease, what is the amount of the lease liability on January 1, 2019 before the lease payment
Determine the nominal rate compounded monthly : Jesse owes $9400, he repays the debt with 7 quarterly payments of $1880.00. Using linear interpolation determine the nominal rate compounded monthly
Building and debugging application : Building and Debugging Application - Create a new C# class with the name CalcFactorial. New Project | Windows Desktop | Console
What is the purpose of the image : What is the historical context in which the source was produced and viewed? What is the purpose of the image? What messages does it convey?
Discuss whether you would recommend hiring : Discuss whether you would recommend hiring from within the organization or hiring externally.
Design a questionnaire to assess the usability : Design a questionnaire to assess the usability of a search bar on a website. Refer lecture notes for examples - What types of error is each likely to find
Creating a new library : Creating a new library - create a new unit test project for your calculator library. Unit tests are kept in their own class libraries

Reviews

Write a Review

Software Engineering Questions & Answers

  Analyze the term cohesion and couplingin software design

Analyze the term cohesion and couplingin software design. In a good software design, why modules should have low coupling and high cohesion?

  Provide the uml diagrams for the given problem

Provide the UML diagrams for the given problem with clear explanations on the design decisions. Derive detailed Use Case diagram, Class diagram & a sequence diagram and provide an alternative OO design for the same problem

  Analysis and design - functionality of the maze game

Analysis on the use of a development methodology in creating the game describing how did this assist, or make the development of the game more complicated.

  Indirect port addressing capability

Determine how many ports can the Z8000 address in each I/O addressing mode?

  Creating an ipo chart for programming problem

A contractor requires a program that computes and shows the volume of a rectangular pool of constant depth. Complete an IPO chart for this problem.

  Implementing a program in multiple languages

Understanding of various programming languages' features and Understanding of Implementing a program in multiple languages

  You will apply the basic steps of the sdlc to building the

identify and document a full information system for a small company. you will apply the basic steps of the sdlc to

  Write professional level management

Write professional level management, planning, quality assurance and testing documentation for a software system - test management document for multiple levels

  What are systems selection goals

What is systems selection?- What are systems selection goals?- What are reasons for developing software internally versus acquiring it from external sources?

  Draw a top level data flow diagram

Rockland county in Long Island has an active taxi workforce of over 1500 taxi drivers and a very active taxi union. Any licensed taxi driver of Rockland county can become a member of the local taxi union - local 330. Draw a top level data flow di..

  How organization might design and control access to system

Describe the contents of such a knowledge management system for an organization to which you belong. Discuss how your organization might design, create, use and control access to the system.

  Draw a domain class diagram for the system

Domain Class diagram: Draw a domain class diagram for the system. Use case diagram: Based on the above project case description, develop a use case diagram containing all major use cases of the system

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd