You Would Never Know Where The Bug Is

Screenshot from 2016-07-05 13-21-26

If you can’t reproduce the bug you would never know where the bug is!

I realized exactly the same when I have been working on a bug of Bodhi. We were pretty clueless about why the bug has arrived. After working on it for long I now believe that I am able to figure out where the bug is, Though the work is still going on. But we are pretty closer to it now. The current state is https://github.com/fedora-infra/bodhi/issues/855.

If we were not be able to reproduce to the bug we would never know why the bug had arrived and believe me it was not really identifiable this time! So before working on patch for a bug we should always try to reproduce it first.

Why Reproduce Bugs?

If you can’t reproduce the bug you would never know where the bug is. Patch doesn’t work just on guess. You are expected to be failed to create a patch if you fail to reproduce the bug.

If you don’t go through the steps when the bug is arrived it is technically impossible to create a patch. After you know why the bug has arrived it is possible for you to fix it as well. If you can’t reproduce the bug you need to create a patch just guessing the issue and you are not sure whether it is going to work or not! So it is not considered as a good practice.  Make sure you are not wasting your time on creating patch about which you are not sure.

Good Bug Reporting: Generally a good bug report contains all required info like when the bug has arrived, what was expected to happen and what has actually happened.

There are bugs about what we have no idea why they have occurred neither the users nor the developers. But the developers can always figure it out by reproducing the bug i.e, creating the same situation(In non-technical word). We will now see How Can We Reproduce Bugs.

How To Reproduce Bugs?

Unittest!

Unittest is one of the certain ways in order to reproduce bugs. I will show a simple demo.

We will write a simple program to check whether a number is odd or even.

Write the code:

Screenshot from 2016-07-05 20-57-56

Write the test:

Screenshot from 2016-07-05 20-58-08

Test is supposed to fail since 6 is an even number. Now we will see what happens:

Screenshot from 2016-07-05 20-54-52

Now we know why the error has occurred. In order to reproduce bugs we always want our test to fail.

This is just the fundamental of unitesting on reproducing bugs. You will know more when working on real world projects.

We can use Pdb also. Check this to see how you can use it.

For Bodhi I have used unittest and mock testing. Here is the testcase I wrote to reproduce the bug I mentioned above: https://paste.fedoraproject.org/386958.