/** * Created by shentianyi on 2019/08/07. */ @isTest private class ET_Batch3_SchedulerTest { public static String CRON_EXP = '0 0 0 3 9 ? 2032'; //省 private static Address_Level__c al = new Address_Level__c(); //市 private static Address_Level2__c al2 = new Address_Level2__c(); //Account HP private static Account AccountHP = new Account(); //Account Agent1 private static Account AccountAgent1 = new Account(); //User //private static user myUser_test = new user(); //Product2 private static Product2 prod01 = new Product2(); /******************************************************************************************************* *@description testデータ作成 */ private static void setdata(){ //Profile prof = [select Id from Profile where Name ='系统管理员']; //myUser_test = New User(Alias = 'newUserA',Email='newuserA@testorg.com',EmailEncodingKey='UTF-8', LastName='testUserA', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUserA@testorg.com',Work_Location__c = '北京'); //insert myUser_test; //Account 经销商 recordtypeID Id AgencyRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId(); //Account 医院 recordtypeID Id HPRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId(); // 省 al = new Address_Level__c(Name = '東京', Level1_Code__c = 'CN-99', Level1_Sys_No__c = '999999'); insert al; // 市 al2 = new Address_Level2__c(Level1_Code__c = 'CN-99', Level1_Sys_No__c = '999999', Level1_Name__c = '東京', Name = '渋谷区', Level2_Code__c = 'CN-9999', Level2_Sys_No__c = '9999999', Address_Level__c = al.id); insert al2; AccountHP = new Account(name='testHP001',RecordTypeId = HPRecordTypeId, Is_Active__c = '有効', Attribute_Type__c = '卫生部', Speciality_Type__c = '综合医院', Grade__c = '一级', OCM_Category__c = 'SLTV', Is_Medical__c = '医疗机构', State_Master__c = al.id, City_Master__c = al2.id, Town__c = '东京'); insert AccountHP; AccountAgent1 = new Account(name='testAgent001',RecordTypeId = AgencyRecordTypeId ); insert AccountAgent1; prod01 = new Product2(Name='Test01', ProductCode='Test01', Asset_Model_No__c = 'Test01', SFDA_Status__c = '有効', Dealer_special_Object__c = true, Family = 'ET', Category2__c = '耗材', Category3__c = 'ERCP', Category4__c = '导丝', Category5__c = 'Visiglide35'); insert prod01; } private static testMethod void test_method_one() { setdata(); Test.startTest(); // Schedule the test job String jobId = System.schedule('ET_Batch3_SchedulerTest', CRON_EXP, new ET_Batch3_Scheduler()); // Get the information from the CronTrigger API object CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE Id = :jobId]; // Verify the expressions are the same System.assertEquals(CRON_EXP, ct.CronExpression); // Verify the job has not run System.assertEquals(0, ct.TimesTriggered); // Verify the next time the job will run System.assertEquals('2032-09-03 00:00:00', String.valueOf(ct.NextFireTime)); Test.stopTest(); } }