我需要一些关于编写测试脚本的帮助,该脚本涵盖了我设法在我的 Sandbox 帐户上工作的足够多的以下触发器。触发器是在某些类型的机会关闭时创建额外的资产。触发器似乎运行良好,但我真的不知道如何开始编写测试用例......为了关闭这些机会,帐户需要完成以下内容(我已经包含了一些示例数据 - 它们是选项列表,所以需要具体数量):
a.TurnoverBand__c = '<£10 million';
a.Joining_Fee__c = '£1,920';
a.Annual_Subscription__c = '£1,320';
触发如下:
trigger CreateInclusiveAssetonMembershipWon on Opportunity (after insert, after update)
{
for(Opportunity o: trigger.new)
{
if(o.isWon == true && o.HasOpportunityLineItem == true && ( o.Type == 'A Membership' || o.Type == 'AB Membership' || o.Type == 'A Membership Upgrade' || o.Type == 'AB Membership Upgrade' ) )
{
String opptyId = o.Id;
Asset[] ast = new Asset[]{};
Asset a = new Asset();
{
a = new Asset();
a.AccountId = o.AccountId;
a.Product2Id = '01tA0000003N1pW';
a.Quantity = o.Inclusive_Training_Spaces_Allocated__c;
a.Price = 300;
a.PurchaseDate = o.CloseDate;
a.Status = 'Purchased';
a.Description = 'Allocated Spaces';
a.Name = 'Membership Inclusive Training';
ast.add(a);
}
insert ast;
}
}
}
如果有人可以帮助我解决这个问题,我将不胜感激!
谢谢
到目前为止,此触发器的 ETA 测试脚本:
@isTest
private class TrngAstOppTrigTestSuite {
static testMethod void verifyBehaviorOnInsert_positive() {
Account a = new Account();
a.Name = 'New Test Account';
a.Account_Email__c = 'testemail4trigger@test.co.uk';
a.TurnoverBand__c = '<£10 million';
a.Joining_Fee__c = '£1,920';
a.Annual_Subscription__c = '£1,320';
insert a;
Opportunity o = new Opportunity();
OpportunityLineItem ol = new OpportunityLineItem();
PricebookEntry pbID = [select ID from PricebookEntry];
o.AccountId = a.Id;
o.Name = 'test';
o.Type = 'A Membership';
o.StageName = 'Needs Analysis';
o.CloseDate = date.today();
insert o;
ol.OpportunityId = o.Id;
ol.Quantity = 1;
ol.UnitPrice = 2.00;
ol.PricebookEntryId = pbID.Id;
insert ol;
o.StageName= 'Closed Won';
update o;
delete ol;
delete o;
}
}
如果有人能说我是否朝着正确的方向前进,我将不胜感激。试图消除错误,但如果这无论如何都行不通,显然没有意义。谢谢