Error - Portal account owner must have a role??

I wrote the following test class for a PRM deployment and received this crazy error when running the test:

System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, portal account owner must have a role: []

I searched the message boards but couldn't find any reference to the real culprit. My original thought was that the user being created was causing an error somehow. However, the real problem was that my user was not assigned a role. Hopefully this post saves someone some time tracking down the solution.


 Account a = new Account(Name='Test Account Name');
 insert a;

 Contact c = new Contact(LastName = 'Contact Last Name', AccountId =;
 insert c;

 User user = new User();
 user.ProfileID = [Select Id From Profile Where Name='Some Profile'].id;
 user.EmailEncodingKey = 'ISO-8859-1';
 user.LanguageLocaleKey = 'en_US';
 user.TimeZoneSidKey = 'America/New_York';
 user.LocaleSidKey = 'en_US';
 user.FirstName = 'first';
 user.LastName = 'last';
 user.Username = '';  
 user.CommunityNickname = 'testUser123';
 user.Alias = 't1';
 user.Email = '';
 user.IsActive = true;
 user.ContactId = c.Id;
 insert user;

 System.RunAs(user) {
  // do all of my tests

You will also see this same error (for the same reason) when trying to enable a contact as a partner or customer portal user.