Unfortunately, bugs exist in all software. However, Salesforce’s automated testing capabilities built into the platform allow Software Engineers to very easily reproduce the bug and confirm that it stays fixed.
Whenever a bug is reported, the first action taken is to reproduce the bug. Once the bug is reproduced, simply re-perform the same steps to confirm that a fix has squashed the bug. While troubleshooting the bug, I’d simply follow these reproduction steps manually every time until the bug was fixed.

With Salesforce’s testing capabilities, the bug is reproduced by writing one or more Apex tests. Now, with the click of a button, the tests will run, and if there’s a problem, the tests fail. Since the bug hasn’t been fixed yet, the tests are failing. Eventually, the bug is fixed and when the tests run again, they pass.
The biggest benefit of this approach is regression testing. These tests are run regularly to ensure that any software changes don’t re-introduce the bug. ​

Contrived Bug Example

Let’s look at an Account trigger with a known bug in it. Can you spot the bug?
trigger AccountTrigger on Account (Before Update){
   for (Account account : Trigger.New){
          Account updatedAccount =
          [select id, name, Other_Fields_Here
               from Account
             where Id = :account];
          // do something with updated account
   }
}
Now, here’s a test class to ensure our trigger works as expected.
@isTest
private class TestAccountTrigger {
  static testmethod void updateTriggerTest(){
      Account a = DataFactoryAccount.insertAccount();
      a.Field_To_Update = updated_value;
      update a;
      // assert expected changes
  }
  // other test methods here
}

Bug Reported: ​

When many accounts are updated simultaneously, a “Too Many SOQL Statements” error is shown. 
Right off the bat, trying to create a bunch of account records and then updating them manually through point-n-click is going to be impossible. As a result, the TestAccountTrigger is augmented with another test method to reproduce the error. 
    static testmethod void updateTriggerInBulkTest(){
         List<Account> accountsToUpdate = DataFactory.insertAccounts(500);
 
         for (Account accountToUpdate : accountsToUpdate){
              accountToUpdate.Field_To_Update = updated_value;
         }
        // With the current implementation, this is where
        // the Too Many Soql Queries error is thrown.
         update accountsToUpdate;
 
         // assert expected changes
    }

After a little troubleshooting, it becomes apparent that the issue is caused by each account being queried individually in the Account Trigger. Since Salesforce currently only allows 100 SOQL queries in a given Execution Context, updating more than 100 accounts causes the “Too Many Soql Queries” error to be thrown.
Luckily, the bug fix is straight-forward. The trigger becomes
trigger AccountTrigger on Account (Before Update){
  List<Account> updatedAccounts =
         [select id, name, Other_Fields_Here
               from Account
             where Id in :Trigger.New];
   for (Account updatedAccount : updatedAccounts){
          // do something with updated account
   }
}
 
Now the TestAccountTrigger test class is ran again and all the tests pass. The bug has been fixed and going forward the tests will automatically detect if there’s a problem.
Happy Coding & Testing,
Luke