@isTest private class ProcessInstanceSolControllerTest { private static User getUser() { String timenow = Datetime.now().format('yyyyMMddHHmmss'); User user1 = new User(Test_staff__c = true, LastName = 'TestMao', FirstName = 'TestMaoF', Alias = 'hp', CommunityNickname = 'TestMao', Email = 'Test@sunbridge.com', Username = 'Test' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = System.Label.ProfileId_SystemAdmin, Dept__c = '医疗华北营业本部', Job_Category__c = '销售服务', Province__c = '北京'); List p = [Select Id From Profile Where Name = '2S1_销售医院担当']; System.assertEquals(p.size(), 1); System.runAs(new User(Id = Userinfo.getUserId())) { insert user1; } return user1; } static testMethod void testMethod1() { User user = getUser(); System.runAs(user) { SolutionProjectRequirements__c solProject = new SolutionProjectRequirements__c(); solProject.Name = 'Test'; solProject.HospitalOwner__c = user.Id; solProject.Sales_Assistant__c = user.Id; solProject.GIR_Assistant__c = user.Id; solProject.Project_Type__c = '新建大楼'; solProject.Purpose_Proposal__c = '促进销售商谈'; insert solProject; Solution_Programme__c solProgramme1 = new Solution_Programme__c(); solProgramme1.Name = 'test'; solProgramme1.SolutionProjectRequirements__c = solProject.Id; solProgramme1.Business_Promotion__c = user.id; solProgramme1.Confirmation_Result__c = '01采纳/部分采纳'; solProgramme1.Remarks__c = 'test'; insert solProgramme1; Approval.ProcessSubmitRequest r = new Approval.ProcessSubmitRequest(); r.setObjectId(solProgramme1.Id); Approval.process(r); String strid = r.getSubmitterId(); PageReference page = new PageReference('/apex/ProcessInstance?id='+strid+'&SolId='+solProgramme1.Id); System.Test.setCurrentPage(page); ProcessInstanceSolController proInSol = new ProcessInstanceSolController(); proInSol.ApprovalAction = 'Approve'; proInSol.Approval(); } } }