I tried this Test Class for my trigger but I always have 0% as coverage , some help please => Trigger
trigger AfterUpdate on OBJ__c (after update) {
Id currentUser = UserInfo.getUserId();
Id currentUserProfileId = userinfo.getProfileId();
String profileName = [SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId()].Name;
for(OBJ__c OBJ: trigger.new)
{
if ( profileName == 'MyProfile1' || profileName == 'MyProfile2'
)
{
if(OBJ.Statut__c == 'Next' )
{
OBJ.Statut__c.addError(' can t modifie');
}
}
}
}
=> Test Class
@isTest
public with sharing class Triggers_Test {
@isTest(seeAllData=true)
public static void testAllTriggers(){
Test.startTest();
String uniqueUserName = 'standarduser' + DateTime.now().getTime() + '@testo.com';
Profile p = [SELECT Id FROM Profile WHERE Name='MyProfile2'];
User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles',
UserName=uniqueUserName);
System.runAs(u) {
List<OBJ__c > obj= new List<OBJ__c >();
insert obj;
update obj;
delete obj;
}
Test.stopTest();
}
}
runAs
user's details are actually being made accessible throughUserInfo
in your trigger?SeeAllData=true
?