DEV Community

Sloan the DEV Moderator
Sloan the DEV Moderator

Posted on

How do you test and find bugs in an application?

This is an anonymous post sent in by a member who does not want their name disclosed. Please be thoughtful with your responses, as these are usually tough posts to write. Email if you'd like to leave an anonymous comment or if you want to ask your own anonymous question.

I'm curious - how do y'all look for bugs in your applications? Trying to figure out new ways to get rid of bugs in my programs, and I'm all ears to hear different methods.

Top comments (14)

bradtaniguchi profile image

So finding bugs and getting rid of them are different tasks with different goals.

finding bugs

  • manually test your code under normal usage
  • write tests/code to automatically test your code automatically
  • use software to "watch" real users use your software and report any errors they see

fixing bugs

  • gather context to what the bug/error represents and means
  • understand what the code is currently doing, while trying to ignore what you think its supposed to be doing (assumptions are the root of all bugs)
  • reliably reproduce in a situation where you can test solutions
  • fix! (or attempt to fix) and validate

Each bullet point above has multiple options on their own. For example writing tests for your code could range from unit tests, to more "realistic" testing where you simulate actual user actions.

valeriavg profile image

I make a manual test checklist and automate what I can from there.

For backend - smoke and soak testing is really helpful, I use k6; they also have a nice explanation on load testing in general in the docs.

For the front-end - end to end testing, but it's slowest and hardest to setup imho, though it is really good for bug chasing.

And in terms of unit tests - fuzzy testing is really helpful.

mellen profile image
Matt Ellen

I read Eric Lippert's "How to Debug Small Programs" and it's got some good advice.

His first piece of advice really hits home: "Turn on compiler warnings" (and read them).

If it's a runtime bug and there are no errors or warnings from the compiler, I'll check what exceptions are thrown. In .NET on Windows you can use the event viewer to see details of exceptions even in release software. For JavaScript, the browser console often has useful information.

If it's a behavioural bug, i.e. not crashing, just doing something unexpected or out of spec, I'll try and track down where in the code it is happening. This is why modular and OO design is so important. It helps prevent the code base from becoming a big ball of mud.

At this point it's important to write down your assumptions of what a particular piece of code is meant to do and figure out a way you can test those assumptions.

ben profile image
Ben Halpern • Edited

Eliminating variables is a great technique in a lot of cases. You can't always find yourself in a circumstance where this makes sense, but when you can just remove lines of code to isolate what the problem might be, you're cooking with gas. Eventually you'll stumble into the problem area and you can go from there.

When you have the opportunity to — it never hurts to write tests during the debugging process. Automated tests are good to have around where bugs were because there are probably nearby bugs, so if your debugging process includes testing, all the better!

ashleyjsheridan profile image
Ashley Sheridan

A few different ways I've had bugs found in the past:

  • Through code. This is language dependent, but for example, moving from Javascript to Typescript introduces some type safety features. Some languages, like PHP, have these features but they're optional. Using them can catch some issues in code
  • Tests, such as unit, functional, and integration tests. These can help check that code is doing what we expect it to. It's important to test that things fail in the way we expect too when we pass in bad data.
  • Manual testing by a developer, or even a QA. This kind of testing can find things that aren't immediately obvious issues from a code POV
  • UAT testing, if the system is going to be used by other users, like external clients, for example

Once any bugs are found, it's usually a case of doing a few things to debug them and fix them:

  • Analysing log files. Most languages/frameworks will log serious issues by default
  • Poor-mans debugging by printing/echoing/loggin variables at different points of code execution
  • Using a full on process debugger which allows you to step through the code using your IDE. PHPStorm, Netbeans, and Visual Studio (not Visual Studio Code, unless you use extra plugins) can do this, but either spinning up a debuggin instance or attaching to a running process
nombrekeff profile image

It's varies depending on the type of software you're writing, it's different to do it for an API, website or when you program for let's say a chip or hardware device.

But in my case (for web and mobile apps), at work we do it in a couple of ways:

  • Finding bugs is done by, writing tests (unit and integration tests), and manual testing. Writing unit tests will make bugs show if done correctly, but you need to know how to write good tests. In manual testing (by other people, not the devs) is a really good way to find bugs. Developers tend to follow the same patterns when trying the app, so by making other people test the app, things the developers missed or are not in their process show up.
  • Fixing bugs can be a bit trickier depending on the bugs, but I tend to follow a simple process similar to what has been pointed out in other comments. First detect where the bug is, then try to understand why it's happening, then add tests that replicate the bug (never asume you know the cause, verify it). Then you can fix it and have tests to validate that the bug is fixed. Note that some complex bugs are not located in one specific file or part of the code so for those bugs you would need to create a more solid test suite to be sure you're not breaking anything else.
drsensor profile image

There is many ways for finding bugs but I found mutation testing to be the quickest path when in doubt. It's slow to execute the tests but also very practical although it will give you many false positive.
As for fixing bugs, understanding the code is a must and this take more time than writing the implementation from scratch. Debugger and log trace will help but it's not guaranteed. Replayability play a big role so rewriting that buggy parts in separate code or environment will help fixing the tough bugs.

cicirello profile image
Vincent A. Cicirello
  1. Automated tests. Running all tests whenever introducing anything new. When you or your users eventually discover bugs that slipped past your existing tests, add test cases that reveal the bug before fixing it.

  2. Use a code coverage tool. Look at the report and examine what your test cases don't cover. Ask yourself why your tests don't cover whatever they don't cover. Some of it might be stuff involving user interaction that is hard to automate testing. But if you find large complex branches not touched by your tests, you found a place where bugs might be lurking. Keep in mind high test coverage, even 100% coverage, doesn't guarantee no bugs. But it can be useful to find places where your tests neglect.

  3. Use static analysis tools. There are several that integrate well with GitHub such as Snyk, Sonatype's Lift, and CodeQL. You can discover potentially errorprone code with tools like these.

  4. Code reviews put extra sets of human eyes on your code.

mishrapraveen profile image
Praveen Mishra

Impressive article on testing and bug discovery in applications! If you're eager to enhance your bug-finding skills, I highly recommend checking out this insightful piece on how to find bugs in Android apps. You can find the article here: How to Find Bugs in Android Apps. Happy testing and happy bug hunting!

mellen profile image
Matt Ellen

If you find a bug you burn down the code base?

Interesting solution, but effective!

liviufromendtest profile image
Liviu Lupei

There are some best practices for Software Testing mentioned in the ISTQB Foundation Level course.
The materials for that course are free and available online.

passpappu079 profile image

If I am reading this correctly, the latter states that you file every bug in the user story? We always create a Bug and link it to the User Story. This way you can track the bugs lifecycle