@isTest private class Consumabledet2upTest { static testMethod void testMethod1() { // TO DO: implement unit test List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店']; if (rectCo.size() == 0) { return; } Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证']; StaticParameter.ConsumableAssetHanderTrigger = true; Account myAccount2 = new Account(name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id); insert myAccount2; Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',JANCODE__c = '04953170200311',Dealer_special_Object__c = true); insert new Product2[]{prod01}; Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id); insert new Product2__c[] {pro1}; //订单 Consumable_order__c Order1 = new Consumable_order__c(); Order1.Name = 'OCM_01_001'; Order1.Order_status__c = '批准'; Order1.Order_type__c = '订单'; Order1.Dealer_Info__c = myAccount2.Id; Order1.RecordTypeid = System.Label.RT_ConOrder_Delivery; Order1.Total_num__c = 3; Order1.OrderNumber_arrived__c =1; Order1.Delivery_detail_count__c=1; Order1.Order_ProType__c = 'ET'; insert Order1; //发货明细 //到货正确信息 Consumable_order_details2__c Orderdet1 = new Consumable_order_details2__c(); Orderdet1.Name = 'OCM-150P-001002'; Orderdet1.Consumable_order_minor__c = Order1.Id; Orderdet1.Consumable_Arrived_order__c = Order1.Id; Orderdet1.Consumable_Product__c = pro1.Id; Orderdet1.Asset_Model_No__c = 'Test01'; Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery; Orderdet1.TracingCode__c = 'BXJRA'; Orderdet1.SerialLotNo__c = '5ZK'; Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRA'; Orderdet1.Arrive_date__c = Date.today(); //发货明细 //到货正确信息 Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c(); Orderdet2.Name = 'OCM-150P-001002'; Orderdet2.Consumable_order_minor__c = Order1.Id; Orderdet2.Consumable_Arrived_order__c = Order1.Id; Orderdet2.Consumable_Product__c = pro1.Id; Orderdet2.Asset_Model_No__c = 'Test01'; Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery; Orderdet2.TracingCode__c = 'BXJRB'; Orderdet2.SerialLotNo__c = '5ZK'; Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRB'; Orderdet2.Arrive_date__c = Date.today(); //发货明细 //到货正确信息 Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c(); Orderdet3.Name = 'OCM-150P-001002'; Orderdet3.Consumable_order_minor__c = Order1.Id; Orderdet3.Consumable_Arrived_order__c = Order1.Id; Orderdet3.Consumable_Product__c = pro1.Id; Orderdet3.Asset_Model_No__c = 'Test01'; Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery; Orderdet3.TracingCode__c = 'BXJRB'; Orderdet3.SerialLotNo__c = '5ZK'; Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRB'; Orderdet3.Arrive_date__c = Date.today(); //发货明细 //到货正确信息 Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c(); Orderdet4.Name = 'OCM-150P-001002'; Orderdet4.Consumable_order_minor__c = Order1.Id; Orderdet4.Consumable_Arrived_order__c = Order1.Id; Orderdet4.Consumable_Product__c = pro1.Id; Orderdet4.Asset_Model_No__c = 'Test01'; Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery; Orderdet4.TracingCode__c = 'BXJRB'; Orderdet4.SerialLotNo__c = '5ZK'; Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRB'; Orderdet4.Arrive_date__c = Date.today(); //发货明细 //到货正确信息 Consumable_order_details2__c Orderdet5 = new Consumable_order_details2__c(); Orderdet5.Name = 'OCM-150P-001002'; Orderdet5.Consumable_Arrived_order__c = Order1.Id; Orderdet5.Consumable_Product__c = pro1.Id; Orderdet5.Asset_Model_No__c = 'Test01'; Orderdet5.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery; Orderdet5.TracingCode__c = 'BXJRC'; Orderdet5.SerialLotNo__c = '5ZK'; Orderdet5.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRC'; Orderdet5.Arrive_date__c = Date.today(); Orderdet5.Dealer_Info_IF__c = myAccount2.Id; insert new Consumable_order_details2__c[] {Orderdet1,Orderdet2,Orderdet3,Orderdet4,Orderdet5}; System.Test.StartTest(); List testid = new List(); testid.add('BXJRB'); Id execBTId = Database.executeBatch(new Consumabledet2up(null), 10); //Id execBTId = Database.executeBatch(new Consumabledet2up(null), 2); System.Test.StopTest(); Consumable_order_details2__c cod1 = [select Id,Agencyinfo_fromSAP__c,Frist_Storage_Agency__c from Consumable_order_details2__c WHERE Id = :Orderdet1.Id]; System.assertEquals('Testaccount002', cod1.Agencyinfo_fromSAP__c); System.assertEquals('Testaccount002', cod1.Frist_Storage_Agency__c); } }