Hi Pranav,Use the below code to assign portal user in test class.
ID ProfileID = [ Select id from Profile where name = ‘Customer Portal Manager Custom’].id;
Account acc = new Account(Name = ‘Test Account’);
insert acc ;
List<Contact> ContactList = new List<Contact>();
Contact Con = new Contact( AccountID = acc .id, FirstName = ‘User’, LastName = ‘test’,
email = ‘testuser@xyz.com’ );
insert Con;
User u = new User( email=’testuser@xyz.com’, contactid = Con.id, profileid = profileid, UserName=’testuser@xyz.com’, alias=’tuser’, CommunityNickName=’tuser’,
TimeZoneSidKey=’America/New_York’, LocaleSidKey=’en_US’, EmailEncodingKey=’ISO-8859-1′,
LanguageLocaleKey=’en_US’, FirstName = ‘User’, LastName = ‘Test’ );
insert u;
Hope this helps you.