如何解决测试顶点类时未创建案例里程碑
最近我偶然发现了获取 Apex 代码的代码覆盖率的问题,该代码通过目标日期值评估案例里程碑。当尝试在测试类中创建案例时,它不会在插入后为其创建案例里程碑,尽管所有条件都已满足在权利过程中定义的内容。
通过阅读文章 - like this about entitlements 似乎我已经创造了一切。 权利流程处于活动状态,关联到案例的关联帐户的权利已创建并链接到案例,营业时间有效,权利流程链接到权利。案例条目标准与里程碑的授权流程中定义的内容相匹配,但仍在测试类中未创建里程碑。
System.debug('案例里程碑 = '+ cmss);语句返回空列表,无法涵盖依赖于案例里程碑目标日期的逻辑。测试数据中是否缺少某些内容?
测试类示例:
@IsTest 私有类 GetCaseTest {
@TestSetup
static void createTestData(){
Profile p = [SELECT Id FROM Profile WHERE Name='Customer Service Lightning'];
UserRole role = [SELECT ID,Name FROM UserRole WHERE Name Like 'NO%' LIMIT 1];
System.debug('@role: ' + role);
User u = new User(
Alias = 'standt',Email='testmail@test.com',EmailEncodingKey='UTF-8',FirstName='Test',LastName='Testing',LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId = p.Id,UserRoleId=role.Id,TimeZonesidKey='America/Los_Angeles',UserName='testmail@test.com'
);
insert u;
Group g = new Group(
Name='NO CS',Type = 'Queue'
);
insert g;
queuesobject q1 = new queuesobject(SObjectType = 'Case',queueid=g.id);
insert q1;
GroupMember member = new GroupMember();
member.UserOrGroupId = u.Id;
member.GroupId = g.Id;
insert member;
}
@isTest
static void getCaseFuture(){
User u = [SELECT Id,Email FROM User WHERE Email = 'testmail@test.com'].get(0);
System.runAs(u){
Id accRecType = Schema.sobjectType.Account.getrecordtypeInfosByName().get('B2B Account').getrecordtypeId();
Account acc = new account(name='Test Account',recordtypeId= accRecType,OwnerId = u.Id);
insert acc;
Contact oContact = new contact(firstname='John',lastname='Doe',email='test@test.com',accountid=acc.id,OwnerId = u.Id);
insert oContact;
Entitlement entl = new entitlement(name='NO Entitlement',StartDate=Date.valueof(System.Now().addDays(-2)),EndDate=Date.valueof(System.Now().addYears(2)));
insert entl;
List<SlaProcess> lstEntitlementProcess = [SELECT Id,Name FROM SlaProcess WHERE Name='NO Entitlement Process 1.3' and IsActive = true LIMIT 1];
System.debug('lstEntitlementProcess= '+lstEntitlementProcess);
entl.SlaProcessId = lstEntitlementProcess[0].id;
update entl;
BusinessHours bhours = [SELECT Id,Name FROM BusinessHours WHERE Name = 'NO Customer Service'].get(0);
Id recordtypeId = Schema.sobjectType.Case.getrecordtypeInfosByName().get('Card Administration').getrecordtypeId();
Group g = [SELECT Id FROM Group WHERE Type = 'Queue' AND Name = 'NO CS'].get(0);
Case c2 = new Case(
Subject = 'To be distributed from queue',Status = 'In Progress',Case_Re_opened__c = false,OwnerId = g.Id,CurrencyIsoCode = 'EUR',Country__c = 'NO',Case_Category__c = 'Card Block',recordtypeId = recordtypeId,AccountId = acc.Id,ContactId = oContact.Id,EntitlementId = entl.Id,slaStartDate=system.Now(),BusinessHoursId = bhours.Id
);
insert c2;
List<CaseMilestone> cmss = [SELECT Id,CaseId FROM CaseMilestone WHERE CaseId =: c2.Id];
System.debug('case milestones = '+ cmss);
System.debug('c2 = '+ c2);
System.debug('c2.OwnerId=> '+ c2.OwnerId);
}
Test.starttest();
GetCase.findCase();
// GetCase.findCase();
Test.stoptest();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。