gpt4 book ai didi

web-services - future 方法销售人员的测试覆盖率

转载 作者:行者123 更新时间:2023-12-02 15:39:14 26 4
gpt4 key购买 nike

您好,我试图覆盖一个几乎没有 future 方法(用于 Web 服务调用)和几个具体静态方法的类。但是在调用 future 的方法之后,我无法调用其他方法...你能告诉我如何覆盖 future 的方法和网络服务调用吗?

我的类(class)结构:

public with sharing class AccountSynchController { 
@future (callout=true)
public static void importAccount(Set<Id> ids) {

}
@future (callout=true)
public static void importContact(Set<Id> ids) {

}
}

[future methods are called from trigger]

Test Class Code :


VAT__c testVat = new VAT__c();
testVat.Code__c = '3';
insert testVat;

Account testAccount = new Account();
testAccount.Name = 'Test Account';
testAccount.VATSales__c = testVat.Id;
testAccount.VATPurchase__c = testVat.Id;
testAccount.KvK_Nummer__c = '12312312';
testAccount.PhoneExt__c = '12312312';
testAccount.Website = '12312312';
testAccount.BillingPostalCode = '12312312';
testAccount.BillingCity = '12312312';
testAccount.Fax = '12312312';
testAccount.Phone = '12312312';
testAccount.BillingStreet = '12312312';
testAccount.BTW_Nummer__c = '12312312';
testAccount.BillingCountry = '12312312';
testAccount.BillingState = '12312312';
testAccount.BTW_Nummer__c = '12312312';
testAccount.E_mail__c = 'test@gmail.com';
testAccount.Taal__c = 'NL';
testAccount.SalesPaymentConditionCode__c = '15';
testAccount.Code__c = '102';
testAccount.fromExact__c = false;
testAccount.Exact_Id__c = '123123';
insert testAccount;

Contact testContact = new Contact();
testContact.AccountId = testAccount.Id;
testContact.Birthdate = system.today();
testContact.Conact_Exact_Number__c = '12312312312';
testContact.Email = 'test@gmail.com';
testContact.FirstName = 'first';
testContact.Title_Code__c = 'Mr.';
testContact.Geslacht__c = 'M';
testContact.Initials__c = 'I';
testContact.Language_Code__c = 'NL';
testContact.LastName = 'last';
testContact.MiddleName__c = 'middle';
testContact.Phone = '12321312312';
testContact.fromExact__c = false;
insert testContact;

谢谢..

最佳答案

通过调用 Test.startTest() 开始您的单元测试,然后运行您的测试插入。调用 Test.stopTest() 完成.调用最后一个方法可确保您的@future 方法将被触发。之后,您可以执行断言来验证触发器的操作。

关于web-services - future 方法销售人员的测试覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11310177/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com