Im getting above error when i was trying to run my test class. In my test class i will create an Account, Contact. And this contact id will be used in my original code to create Community user. I noticed following help article from SFDC. But couldn't figure out how to achieve. https://help.salesforce.com/HTViewSolution?id=000175522&language=en_US
Here they asked to create User on the Test class and Runas this user. But in my case, the community user will be created in the code. Please share any thoughts. Here is the detailed exception,
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, caused by: System.DmlException: Insert failed. First exception on row 11; first error: UNKNOWN_EXCEPTION, portal account owner must have a role: []