This is the Trigger that I am trying to get code coverage for, but my test class is failing.Both testMethods are passing, but it's saying "No Code Coverage". So I guess my two test methods aren't really testing anything? Can someone help explain where I am going wrong, or what I am missing? Thanks!
Trigger
trigger FinanceApprovalAdDirector on Rate_Request__c (before insert,before update) {
for(Rate_Request__c fa: trigger.new)
{
Market__c m = [Select Ad_Director__c From Market__c WHERE Unit_Number__c = :fa.Owner_Market__c];
fa.Ad_Director__c = m.Ad_Director__c;
User u = [Select ManagerId From User WHERE Id = :UserInfo.getUserId()];
fa.Manager__c = u.ManagerId;
}
}
My Test Class
@isTest(SeeAllData=true)
public class FinanceApprovalAdDirectorTest{
static testMethod void testRateRequestManager(){
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
User u1 = new User(Alias = 'standt1', Email='[email protected]', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
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='[email protected]', ManagerId = u1.id);
System.runAs(u){
Market__c m = new Market__c();
m.Unit_Number__c = '1111';
m.Name = 'test';
m.Ad_Director__c = u.id;
insert m;
Market__c mTest = [SELECT Ad_Director__c, Unit_Number__c, Name FROM Market__c WHERE Unit_Number__c = :m.Unit_Number__c];
test.startTest();
Rate_Request__c rr = new Rate_Request__c();
rr.Ad_Director__c = mTest.Ad_Director__c;
rr.Manager__c = u.ManagerId;
System.assertEquals(u1.id, rr.Manager__c);
System.assertNotEquals(u.id, rr.Manager__c);
test.stopTest();
}
}
static testMethod void testRateRequestAdDirector(){
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
User u = new User(Alias = 'standt1', Email='[email protected]', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
User u1 = 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='[email protected]', ManagerId = u.id);
System.runAs(u){
Market__c m = new Market__c();
m.Unit_Number__c = '1111';
m.Name = 'test';
m.Ad_Director__c = u.id;
insert m;
Market__c mTest = [SELECT Ad_Director__c, Unit_Number__c, Name FROM Market__c WHERE Unit_Number__c = :m.Unit_Number__c];
test.startTest();
Rate_Request__c rr = new Rate_Request__c();
rr.Ad_Director__c = mTest.Ad_Director__c;
System.assertEquals(u.id, rr.Ad_Director__c);
System.assertNotEquals(u1.id, rr.Ad_Director__c);
test.stopTest();
}
}
}
SeeAllData=true
- mock all data needed by testmethods.SeeAllData=true
can lead to failed deployments now or in the future