title: Test Coverage fails on before insert / before update Apex trigger
body: <p>I have this very simple before insert / update trigger on Opportunity that auto-selects the Price Book based on a dropdown value containing Sales Office (State) location info. </p>
  
  <p>Here's my <strong>Trigger</strong>:</p>
  
  <pre><code>trigger SelectPriceBook on Opportunity ( before insert, before update ) {
  
      for( Opportunity opp : Trigger.new ) {
          // Change Price Book
          // New York
          if( opp.Campus__c == 'NYC' )
            opp.Pricebook2Id = PB_NYC; // contains a Pricebook's ID
  
          // Atlanta
          if( opp.Campus__c == 'ATL' )
            opp.Pricebook2Id = PB_ATL; // contains another Pricebook's ID
      }
  }
  </code></pre>
  
  <p>Here's my <strong>Test Class</strong>:</p>
  
  <pre><code>@isTest (SeeAllData = true)
  public class SelectPriceBookTestClass {
  
      static testMethod void validateSelectPriceBook() {
  
          // Pricebook IDs
          ID PB_NYC =  'xxxx';
          ID PB_ATL =  'xxxx';
  
          // New Opp
          Opportunity opp = new Opportunity();
          opp.Name = 'Test Opp';
          opp.Office__c = 'NYC';
          opp.StageName = 'Quote';       
  
          // Insert
          insert opp;
  
          // Retrive inserted opportunity
          opp = [SELECT Pricebook2id FROM Opportunity WHERE Id =:opp.Id];
          System.debug( 'Retrieved Pricebook Id: ' + opp.Pricebook2Id );
  
          // Change Campus
          opp.Office__c = 'ATL';
          // Update Opportunity
          update opp;
  
          // Retrive updated opportunity
          opp = [SELECT Pricebook2id FROM Opportunity WHERE Id =:opp.Id];
          System.debug( 'Retrieved Updated Pricebook Id: ' + opp.Pricebook2Id );        
  
          // Test
          System.assertEquals( PB_ATL, opp.Pricebook2Id );
  
      }
  }
  </code></pre>
  
  <p>The test runs report <strong>0% test coverage</strong>. </p>
  
  <p>Also, on similar lines I have another before insert trigger that sets the Owner of an Event same as the Owner of the parent Lead.  Here's the code:</p>
  
  <pre><code>trigger AutoCampusTourOwner on Event( before insert ) {
  
      for( Event evt : Trigger.new ) {
          // Abort if other kind of Event
          if( evt.Subject != 'Visit' )
              return;        
  
          // Set Owner Id
          Lead parentLead = [SELECT OwnerId FROM Lead WHERE Id = :evt.WhoId];
          evt.OwnerId = parentLead.OwnerId;
  
      }
  }
  </code></pre>
  
  <p>This, too, is causing 0% coverage - my guess is that it's got something to do with the <strong>for</strong> loops in both. I know I'm seriously flouting DML rules by invoking SOQL query inside a for loop, but for my purposes it should be fine as these Events are created manually and only one at a time - so there are no scopes of governor limits kicking in due to bulk inserts.</p>
  
  <p>The code in both cases work 100%. Please suggest a fix for the test cases. </p>