/** * This class contains unit tests for validating the behavior of Apex classes * and triggers. * * Unit tests are class methods that verify whether a particular piece * of code is working properly. Unit test methods take no arguments, * commit no data to the database, and are flagged with the testMethod * keyword in the method definition. * * All test methods in an organization are executed whenever Apex code is deployed * to a production organization to confirm correctness, ensure code * coverage, and prevent regressions. All Apex classes are * required to have at least 75% code coverage in order to be deployed * to a production organization. In addition, all triggers must have some code coverage. * * The @isTest class annotation indicates this class only contains test * methods. Classes defined with the @isTest annotation do not count against * the organization size limit for all Apex scripts. * * See the Apex Language Reference for more information about Testing and Code Coverage. */ @isTest private class SS_MonthlySubmitDailyReportBatchTest { static testMethod void myUnitTest() { Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; // ユーザー作成 User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id, Province__c = '北京市', Product_specialist_incharge_product__c = 'ALL', Job_Category__c = '销售推广', //Salesdepartment__c, //Fiscal_Start_Date__c, Use_Start_Date__c = date.today()); insert hpOwner; List ssMonthlySubmitDailyReportList = new List { new SS_monthly_submit_daily_report__c( OwnerId = hpOwner.Id ), new SS_monthly_submit_daily_report__c( OwnerId = hpOwner.Id ), new SS_monthly_submit_daily_report__c( OwnerId = hpOwner.Id ) }; insert ssMonthlySubmitDailyReportList; System.Test.StartTest(); Id execBTId = Database.executeBatch(new SS_MonthlySubmitDailyReportBatch(), 50); System.Test.StopTest(); // assert List bList = [select Id, Province_Text__c, Product_specialist_incharge_product_text__c, Job_Category_Text__c, Salesdepartment_Text__c from SS_monthly_submit_daily_report__c]; System.assertEquals(3, bList.size()); SS_monthly_submit_daily_report__c tmp = bList[0]; System.assertEquals('北京市', tmp.Province_Text__c); System.assertEquals('ALL', tmp.Product_specialist_incharge_product_text__c); System.assertEquals('销售推广', tmp.Job_Category_Text__c); System.assertEquals('1.华北', tmp.Salesdepartment_Text__c); } }