@isTest private class CloseInventoryTaskBatchTest { static testMethod void testMethod1() { try{ StaticParameter.EscapeContactToUser = true; Oly_TriggerHandler.bypass('UserProfileHandler'); Oly_TriggerHandler.bypass(UserProfileHandler.Class.getName()); List records=[Select id,name from RecordType where name='盘点检查计划' or name = '温湿度检查计划']; List tasks = new List(); task__c t1 = new task__c(); t1.Name = 'test1'; t1.taskDifferent__c = '主动任务'; t1.taskStatus__c = '01 分配'; t1.assignee__c = Userinfo.getUserId(); t1.delayToDate__c=Date.today(); if(records.size()>0){ t1.RecordTypeId=records.get(0).Id; } tasks.add(t1); task__c t2 = new task__c(); t2.Name = 'test1'; t2.taskDifferent__c = '主动任务'; t2.taskStatus__c = '05 延期'; t2.assignee__c = Userinfo.getUserId(); t2.delayToDate__c=SYstem.today(); if(records.size()>0){ t2.RecordTypeId=records.get(0).Id; } tasks.add(t2); task__c t3 = new task__c(); t3.Name = 'test1'; t3.taskDifferent__c = '主动任务'; t3.taskStatus__c = '05 延期'; t3.assignee__c = Userinfo.getUserId(); t3.delayToDate__c=SYstem.today(); if(records.size()>0){ t3.RecordTypeId=records.get(0).Id; } tasks.add(t3); System.runAs(new User(Id = Userinfo.getUserId())) { System.Test.startTest(); insert tasks; // List taskList=[ // SELECT Id, taskStatus__c // FROM task__c // WHERE taskStatus__c = '01 分配' // AND (RecordType.Name = '盘点检查计划' OR RecordType.Name = '温湿度检查计划')]; Database.executeBatch(new CloseInventoryTaskBatch(), 100); System.Test.stopTest(); } }catch(Exception e){ } } static testMethod void testMethod2() { StaticParameter.EscapeContactToUser = true; Oly_TriggerHandler.bypass('UserProfileHandler'); Oly_TriggerHandler.bypass(UserProfileHandler.Class.getName()); List records=[Select id,name from RecordType where name='盘点检查计划' or name = '温湿度检查计划']; List tasks = new List(); task__c t1 = new task__c(); t1.Name = 'test1'; t1.taskDifferent__c = '主动任务'; t1.taskStatus__c = '01 分配'; t1.assignee__c = Userinfo.getUserId(); if(records.size()>0){ t1.RecordTypeId=records.get(0).Id; } tasks.add(t1); System.runAs(new User(Id = Userinfo.getUserId())) { System.Test.startTest(); insert tasks; // List taskList=[ // SELECT Id, taskStatus__c // FROM task__c // WHERE taskStatus__c = '01 分配' // AND (RecordType.Name = '盘点检查计划' OR RecordType.Name = '温湿度检查计划')]; Database.executeBatch(new CloseInventoryTaskBatch(), 100); System.Test.stopTest(); } } static testMethod void testMethod3() { StaticParameter.EscapeContactToUser = true; Oly_TriggerHandler.bypass('UserProfileHandler'); Oly_TriggerHandler.bypass(UserProfileHandler.Class.getName()); List records=[Select id,name from RecordType where name='盘点检查计划' or name = '温湿度检查计划']; List tasks = new List(); task__c t1 = new task__c(); t1.Name = 'test1'; t1.taskDifferent__c = '被动任务'; t1.taskStatus__c = '01 分配'; t1.assignee__c = Userinfo.getUserId(); t1.taskTypeFlow__c='中标结果确认'; t1.Task_After_3_WorkDay__c=SYstem.today(); if(records.size()>0){ t1.RecordTypeId=records.get(0).Id; } tasks.add(t1); System.runAs(new User(Id = Userinfo.getUserId())) { System.Test.startTest(); insert tasks; // List taskList=[ // SELECT Id, taskStatus__c // FROM task__c // WHERE taskStatus__c = '01 分配' // AND (RecordType.Name = '盘点检查计划' OR RecordType.Name = '温湿度检查计划')]; Database.executeBatch(new CloseInventoryTaskBatch(), 100); System.Test.stopTest(); } } }