高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * 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<SS_monthly_submit_daily_report__c> ssMonthlySubmitDailyReportList = new List<SS_monthly_submit_daily_report__c> {
            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<SS_monthly_submit_daily_report__c> 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);
    }
}