Xcode 提高测试类覆盖率
任何人都可以帮助我增加代码覆盖率。对于下面的类和测试类 类别:Xcode 提高测试类覆盖率,xcode,testing,salesforce,apex,Xcode,Testing,Salesforce,Apex,任何人都可以帮助我增加代码覆盖率。对于下面的类和测试类 类别: global class Clear_Territory_Flag_Batch implements Database.Batchable<sObject> { global String sql; global Database.QueryLocator start(Database.BatchableContext BC) { sql='select id,Te
global class Clear_Territory_Flag_Batch implements Database.Batchable<sObject> {
global String sql;
global Database.QueryLocator start(Database.BatchableContext BC) {
sql='select id,Territory_Update_Falg__c from opportunity where
Territory_Update_Falg__c=true and lastmodifieddate=today';
return Database.getQueryLocator(sql);
}
global void execute(Database.BatchableContext BC, List<SObject> objs) {
List<Opportunity> Opptys=new List<Opportunity>();
for(Opportunity o:(List<Opportunity>)objs){
o.Territory_Update_Falg__c=false;
Opptys.add(o);
}
if(Opptys.size()>0){
OpportunityTriggerHandler.skipTriggerProcessing = true;
update Opptys;
OpportunityTriggerHandler.skipTriggerProcessing = false;
}
}
global void finish(Database.BatchableContext BC) {
}
}
global类Clear\u Territory\u Flag\u Batch实现数据库。Batchable{
全局字符串sql;
global Database.QueryLocator启动(Database.BatchableContext BC){
sql='select id,Territory\u Update\u Falg\u c from opportunity where
地区更新(Falg)c=true,lastmodifieddate=today’;
返回数据库.getQueryLocator(sql);
}
全局void execute(Database.BatchableContext BC,List objs){
List Opptys=新列表();
对于(机会o:(列表)objs){
o、 地区更新错误c=错误;
机会加(o);
}
如果(Opptys.size()>0){
OpportunityTriggerHandler.skipTriggerProcessing=true;
更新机会;
OpportunityTriggerHandler.skipTriggerProcessing=false;
}
}
全局void完成(Database.BatchableContext BC){
}
}
测试等级:
@isTest(SEEALLDATA=TRUE)
public class TestClear_Territory_Flag_Batch {
static testMethod void testMethod1()
{
List<Opportunity> st=new List<Opportunity>([Select id , Name , Territory_Update_Falg__c from Opportunity where Territory_Update_Falg__c = true ]);
for(integer i=0;i<1500;i++) {
Opportunity t=new Opportunity();
t.Territory_Update_Falg__c = true;
//t.id='0000000123';
st.add(t);
}
Database.BatchableContext bc;
Clear_Territory_Flag_Batch obj =new Clear_Territory_Flag_Batch();
//st=obj.start(b);
obj.execute(bc,st);
obj.finish(bc);
}
}
@isTest(见AllData=TRUE)
公共类TestClear\u Territory\u Flag\u Batch{
静态testMethod void testMethod1()
{
列表st=新列表([从Opportunity中选择id、名称、Territory_Update_Falg_c=true]);
对于(整数i=0;i请检查@isTest
公共类TestClear\u Territory\u Flag\u Batch{
static testMethod void testMethod1()
{
List<Opportunity> oppListToInsert=new List<Opportunity>();
//insert some Opportunity records
for(integer i=0;i<10;i++) {
Opportunity opp=new Opportunity();
opp.Name ='Test Opp'+i;
opp.Territory_Update_Falg__c = true;
//assign every require fields like closedate, stagename etc
oppListToInsert.add(opp);
}
try{
insert oppListToInsert;
}catch(Exception e){
system.debug('******Error in--'+e.getMessage());
}
Clear_Territory_Flag_Batch obj =new Clear_Territory_Flag_Batch();
database.executeBatch(obj,5);
static testMethod void testMethod1()
{
List OPPLISTOINSERT=新列表();
//插入一些Opportunity记录
对于(整数i=0;i
如果(Opptys.size()>0){
Create a new test method for this condition to make this condition false
OpportunityTriggerHandler.skipTriggerProcessing = true;
update Opptys;
OpportunityTriggerHandler.skipTriggerProcessing = false;
}