@isTest private class ConsumApplyCancelControllerTest { // 造出选择完明细的申请 @testSetup static void setupTestData(){ ConsumTestDataFactory factory = new ConsumTestDataFactory(); factory.setupTestData(); } static testMethod void testSaveCancel() { Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c LIMIT 1]; PageReference ref = new PageReference('/apex/ConsumApplyCancel?objId=' + ca.Id); Test.setCurrentPage(ref); ConsumApplyCancelController controller = new ConsumApplyCancelController(); controller.init(); Test.startTest(); // 不填取消理由,取消不成功 controller.ra.Loaner_cancel_request__c = '取消备注'; controller.saveCancel(); ca = [SELECT Id, RA_Status__c FROM Consum_Apply__c LIMIT 1]; System.assertNotEquals('取消', ca.RA_Status__c); System.assertEquals('ng', controller.saveStatus); // 填写理由,取消成功 controller.ra.Cancel_Reason__c = '主动取消'; controller.saveCancel(); ca = [SELECT Id, RA_Status__c FROM Consum_Apply__c LIMIT 1]; System.assertEquals('取消', ca.RA_Status__c); System.assertEquals('ok', controller.saveStatus); Test.stopTest(); } }