What’s Debugging in Software testing and how to do it?

Pepcoding
6 min readFeb 22, 2022

--

No matter what task or what field you are pursuing, you are bound to make mistakes. Because people make mistakes. Now, coming to the context of coding, coders can spend months correcting their mistakes, a process we call debugging in software testing.

Now, debugging is pretty important. In fact, a massive part of being a developer is to know how to fix mistakes- to be a pro at debugging. In this blog, we will share how to be good at debugging:

  • The tools to use
  • Good practices to avoid bugs
  • Some special debugging tips and tricks

What is Debugging?

Bug refers to the error in your code. It’s the thing that leaves programmers staring at their screens for hours. Debugging in Software development is the process of removing that error.

Why Debugging?

It’s easy for programs to have errors. But debugging lets you find precise problem points at the very beginning so you can repair them. Through Debugging, we can save time by avoiding complex one-use testing codes.

Why is it so hated?

Because it’s too painful finding imperfections in your own creation. However, to be a good programmer, you have to be good at finding problems and solving them.

Here are the key steps of Debugging

  • Identifying the problem
  • Sharing it with fellow coders to make sure that the error is legit.
  • Analyzing modeling, finding, and testing candidate flaws.
  • Rectify the errors by taking necessary actions
  • Verify the corrections.

The Approach:

You have to start with understanding the system. This helps you identify the changes made in the system so you can work on them.

The approach can be either forward or backward.

In the forward approach, we trace the breakpoints and print statements starting from the starting of the program and find the defects on breakpoints. In the backward approach, we directly detect the location of failure and go backwards to identify the region of faulty code.

The idea is to print the intermediate values hoping that it will spot the statement causing the error.

Here’s how we can further differentiate between the approaches.

Brute Force Method:

It’s the most used but also the least efficient approach. Here, a program is loaded with print statements to spot the program in error.

Backtracking:

Backtracking uses the backward approach. To find the error, we note where we saw the error symptoms. But with new technologies being made, programmers have to work with complex codes with multiple supply lines. That’s why this approach can also become inept.

Cause removing method:

In this method, you see the error symptom and think of the causes of the errors and then conduct tests to debug those errors.

Once you choose one of the approaches, you have to run your code step by step in the system to identify the problem.

The process of Debugging:

Start with challenging your assumptions. The error might be lying in plain sight and you just have to open your mind to detect it. Here are a few pointers to challenge your assumptions:

Are you assuming the objects and values are correct?

Verify that all the objects and values are exactly what you assume them to be.

Have you chosen the right API?

You have to reevaluate the API you are using. Does it perform the function you want it to do? That’s why it is important to keep documentation of your code on hosting platforms like Github, so you can always go back and reexamine the code.

Is there a typing error?

A small typo can stop your code from working. And it’s all the more frustrating because it is almost unnoticeable.

Good practices to avoid Debugging problems:

  • Start with a small but effective code that fulfills the task. And then modify and add to that code gradually so you can check for bugs at each step of the process.
  • Keep the documentation of your code that you can refer back to.
  • Write unit tests to help the Debugging tool understand the intent of your code.

How to test your code?

Testing lets you examine the state of the code line by line to help you detect where the problem is.

You can test your codes in VS code, one of the most trusted debugging platforms.

Here’s how you can do it:

Press F5 or else here’s what you can do:
Debug > Start Debugging (you can find it in the menu or the button in the Debug Toolbar)

Here’s what you will find:

An exception: If there is an exception, VS Code will point it out to the exact line where the problem is occurring.

No exception: If there is no exception, you can set breakpoints in VS code to study the code more carefully. Breakpoints is the point where the code pauses in VS code.

To create a breakpoint you can click on the left margin next to the line of the code. Or else you can press F9 while placing the cursor on the line breakpoint should be.

Once you have tracked the section where the problem is, click F10 or F11 to inspect the problem code. And run the code in the debugger.

How to Debug your code?

There are a lot of public domain softwares and automated debugging tools to help you debug your code. But overall, Debugging is a very complex process that very often requires you to manually fix the problem. But first, let’s talk about debugging tools.

Tools for debugging:

Tools reproduce situations where an error has occurred. These cool things help you understand code errors, so let us understand them. Here we print the intermediate values hoping that it will spot the statement causing the error.

The approach becomes a lot more systematic if we use a symbolic program. This way, you can check the values of variables easily through breakpoints. GDB and DBX are Debugging software. Code-based tracers, interpreters like Radare2, WinDbg, and Valgrind are debugging tools that coders usually use. But these automated tools don’t always work since each bug needs a different approach to fix it.

More tools to help you in Debugging:

Sometimes you put all your time and focus on debugging, but the error is just not in the mood to leave. In this case, we can take the help of the community. Here go some websites you can visit when you get miserably stuck at code:

Google (The Lord and Saviour)

Google is the holy grail when it comes to answering all your questions from life to accessories to coding. If you are not living in the caves, you must have used it plenty of times already and know it’s power. However, if you still need a heads up, to help you master Google searches and to Google like a pro!

Knowing how to Google can help you save a lot of time in your programming and development process.

Stack Overflow (Developer’s frenimy)

This one you should be careful using because developers can easily abuse it. The platform is to post errors and the community of programmers and developers help it resolve them in little time. So, surely use it, but don’t abuse it!

Github

Github is the pioneer of code hosting platforms that provides you a free cloud to host your code. And it lets you share code with a number of people and work collaboratively which is always a great practice. You can also explore its repositories where you will find extremely valuable content and codes.

There are other platforms as well where you can find resources and clarify your queries. NADOS is a platform that allows you to work collaboratively with a community of friendly fellow coders who are working towards the common goal of becoming better programmers. What’s more you get hiring opportunities through hackathons and hiring contests that can set you up for product based companies. So, check out NADOS to prepare for a lucrative and fulfilling career in programming.

Author: Mansi Sabharwal

Also read:

--

--