Apex 触发器零代码覆盖率
Apex trigger zero code coverage
谁能帮我解决我的问题。
我已经用测试 classes 创建了 apex 触发器。
测试 运行 后我没有收到任何错误,但无法获得任何代码覆盖率。
请检查下面是我的顶点触发和测试 class.
trigger getAllContacts on Scheme__c (after insert,after update)
{
List<ANZSIC_Contact__c> acc = new List<ANZSIC_Contact__c>();
for(Scheme__c scheme :trigger.new)
{
Id devRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Underwriter').getRecordTypeId();
if(scheme.Account__c != null && scheme.Account__r.RecordTypeId== devRecordTypeId )
{
List<Contact> con = new List<Contact>();
con = [select Id,Email,Phone from contact where Account.Id =:scheme.Account__c];
for(Contact c:con)
{
acc = [select Id from ANZSIC_Contact__c where Contact__c =:c.Id and Scheme__c =:scheme.Id];
if(acc ==Null)
{
ANZSIC_Contact__c ac = new ANZSIC_Contact__c();
ac.Contact__c = c.Id;
ac.Scheme__c = scheme.Id;
ac.Email__c = c.Email;
ac.Phone__c = c.Phone;
acc.add(ac);
}
else
{
}
}
insert acc;
}
}
}
@isTest(seeAllData=false)
private class Test_getAllContacts
{
static testMethod void getAllContacts()
{
test.startTest();
RecordType businessAccountRecordType = [SELECT Id FROM RecordType WHERE SobjectType='Account' AND Name = 'Underwriter'];
Account acc = new Account();
acc.Name = 'Test Account';
acc.RecordTypeId = businessAccountRecordType.Id;
insert acc;Contact con = new Contact();
con.LastName = 'Test data';
con.AccountId = acc.Id;
con.Email ='n@yahoo.in';
con.Phone = '987654321';
insert con; Scheme__c sh = new Scheme__c();
sh.Account__c = acc.Id;
test.stopTest();
}
}
可能是我回答的有点晚了,但是...
@isTest(seeAllData=false)
:如果将 seeAllData 设置为 false,您的查询将不会在测试中获取记录类型信息 class!
要么将其设置为 true,要么如果不允许,请在您的测试 class.
中创建记录类型 record/data
谁能帮我解决我的问题。 我已经用测试 classes 创建了 apex 触发器。 测试 运行 后我没有收到任何错误,但无法获得任何代码覆盖率。 请检查下面是我的顶点触发和测试 class.
trigger getAllContacts on Scheme__c (after insert,after update)
{
List<ANZSIC_Contact__c> acc = new List<ANZSIC_Contact__c>();
for(Scheme__c scheme :trigger.new)
{
Id devRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Underwriter').getRecordTypeId();
if(scheme.Account__c != null && scheme.Account__r.RecordTypeId== devRecordTypeId )
{
List<Contact> con = new List<Contact>();
con = [select Id,Email,Phone from contact where Account.Id =:scheme.Account__c];
for(Contact c:con)
{
acc = [select Id from ANZSIC_Contact__c where Contact__c =:c.Id and Scheme__c =:scheme.Id];
if(acc ==Null)
{
ANZSIC_Contact__c ac = new ANZSIC_Contact__c();
ac.Contact__c = c.Id;
ac.Scheme__c = scheme.Id;
ac.Email__c = c.Email;
ac.Phone__c = c.Phone;
acc.add(ac);
}
else
{
}
}
insert acc;
}
}
}
@isTest(seeAllData=false)
private class Test_getAllContacts
{
static testMethod void getAllContacts()
{
test.startTest();
RecordType businessAccountRecordType = [SELECT Id FROM RecordType WHERE SobjectType='Account' AND Name = 'Underwriter'];
Account acc = new Account();
acc.Name = 'Test Account';
acc.RecordTypeId = businessAccountRecordType.Id;
insert acc;Contact con = new Contact();
con.LastName = 'Test data';
con.AccountId = acc.Id;
con.Email ='n@yahoo.in';
con.Phone = '987654321';
insert con; Scheme__c sh = new Scheme__c();
sh.Account__c = acc.Id;
test.stopTest();
}
}
可能是我回答的有点晚了,但是...
@isTest(seeAllData=false)
:如果将 seeAllData 设置为 false,您的查询将不会在测试中获取记录类型信息 class!
要么将其设置为 true,要么如果不允许,请在您的测试 class.
中创建记录类型 record/data