@isTest private class OppLoseControllerTest { static testMethod void testMethod1() { Daily_Report__c dr1 = new Daily_Report__c(); dr1.Reporter__c = UserInfo.getUserId(); dr1.Reported_Date__c = date.today().addDays(-2); dr1.Status__c = '申請中'; insert dr1; Event__c event = new Event__c(); event.ActivityDate__c = date.today().addDays(-2); event.Daily_Report__c = dr1.Id; event.StartDateTime__c = Datetime.newInstance(2021, 8, 17, 10, 0, 0); event.EndDateTime__c = Datetime.newInstance(2021, 8, 17, 17, 0, 0); insert event; Opportunity opp = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today()); opp.Trade__c = '内貿'; //opp.CurrencyIsoCode = CurrencyIso; opp.Sales_Root__c = '販売店'; opp.StageName = '引合'; opp.Fixed_Check__c = false; opp.owner_not_automatically_update__c = true; //opp.Pricebook2Id = pricebook.id; opp.Purchase_Type__c = '一般引合'; opp.Promise_Class__c = '内貿'; opp.Fund_Basis__c = '政府資金'; opp.Wholesale_Price__c = 9000; opp.Opportunity_stage__c = '还没申请预算'; opp.Close_Forecasted_Date__c = Date.today().addDays(50); opp.Special_Opp_lanhai__c = false; insert opp; task__c t1 = new task__c(); t1.Name = 'test1'; t1.taskDifferent__c = '主动任务'; t1.taskStatus__c = '02 接受'; t1.assignee__c = Userinfo.getUserId(); t1.Event__c = event.Id; t1.Daily_Report__c = dr1.Id; t1.Activity_Date__c = Date.newInstance(2021, 7, 17); t1.OpportunityId__c = opp.Id; insert t1; OppLoseController c=new OppLoseController(); OppLoseController.init(t1.Id); OppLoseController.taskOLYwinBid(opp.Id); OppLoseController.taskLoseBid(opp.Id); OppLoseController.init(null); OppLoseController.taskOLYwinBid(null); OppLoseController.taskLoseBid(null); } }