@isTest private class ConsumUploadPictureControllerTest { // 造出已出库 @testSetup static void setupTestData(){ ConsumTestDataFactory factory = new ConsumTestDataFactory(); factory.setupTestData(); factory.selectDetails(); factory.approve(); factory.defaultAssign(); factory.shippmentRequest(); factory.shipment(); } // 正常上传 static testMethod void testSave() { Consum_Apply__c ca = null ; List caesdList = null; caesdList = [SELECT Picture1__c, Picture2__c, Has_Picture__c FROM Consum_Apply_Equipment_Set_Detail__c]; System.assertEquals(null, caesdList[0].Picture1__c); System.assertEquals(null, caesdList[0].Picture2__c); System.assertEquals(false, caesdList[0].Has_Picture__c); PageReference ref = new PageReference('/apex/ConsumUploadPicture?caesd_id=' + caesdList[0].Id); Test.setCurrentPage(ref); ConsumUploadPictureController controller = new ConsumUploadPictureController(); Test.startTest(); controller.init(); controller.caesd.Picture1__c = 'aaa'; controller.caesd.Picture2__c = 'bbb'; controller.save(); controller.goback(); Test.stopTest(); caesdList = [SELECT Picture1__c, Picture2__c, Has_Picture__c FROM Consum_Apply_Equipment_Set_Detail__c]; System.assertEquals('aaa', caesdList[0].Picture1__c); System.assertEquals('bbb', caesdList[0].Picture2__c); System.assertEquals(true, caesdList[0].Has_Picture__c); } // 已消耗的无法上传 static testMethod void testSave1() { Consum_Apply__c ca = null ; ca = [SELECT Id FROM Consum_Apply__c]; ca.HP_received_sign_rich__c = '试用表'; update ca; List caesdList = null; caesdList = [SELECT Picture1__c, Picture2__c, Has_Picture__c FROM Consum_Apply_Equipment_Set_Detail__c]; System.assertEquals(null, caesdList[0].Picture1__c); System.assertEquals(null, caesdList[0].Picture2__c); System.assertEquals(false, caesdList[0].Has_Picture__c); PageReference ref = new PageReference('/apex/ConsumUploadPicture?caesd_id=' + caesdList[0].Id); Test.setCurrentPage(ref); ConsumUploadPictureController controller = new ConsumUploadPictureController(); Test.startTest(); controller.init(); controller.caesd.Picture1__c = 'aaa'; controller.caesd.Picture2__c = 'bbb'; controller.save(); Test.stopTest(); caesdList = [SELECT Picture1__c, Picture2__c, Has_Picture__c FROM Consum_Apply_Equipment_Set_Detail__c]; System.assertEquals(null, caesdList[0].Picture1__c); System.assertEquals(null, caesdList[0].Picture2__c); System.assertEquals(false, caesdList[0].Has_Picture__c); } }