@isTest private class ConsumSelectControllerTest { static testMethod void testUnAssign() { ConsumTestDataFactory factory = new ConsumTestDataFactory(); factory.setupTestData(); factory.selectDetails(); factory.approve(); factory.unAssign(); Consum_Apply_Equipment_Set_Detail__c caesd = [SELECT Id, RAESD_Status__c, Consum_Apply_Equipment_Set__c FROM Consum_Apply_Equipment_Set_Detail__c]; System.assertEquals('待分配', caesd.RAESD_Status__c); PageReference ref = new PageReference('/apex/ConsumSelect?recid=' + caesd.Consum_Apply_Equipment_Set__c); Test.setCurrentPage(ref); ConsumSelectController controller = new ConsumSelectController(); CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl(); cmp.pageController = controller; controller.myComponentController.init(); controller.init(); controller.searchOpp(); System.assertEquals(1, controller.viewList.size()); Test.startTest(); controller.viewList[0].check = true; caesd = (Consum_Apply_Equipment_Set_Detail__c) controller.viewList[0].sobj; caesd.Fen_Pei_Shu_Liang_Jia__c = 1; controller.save(); Test.stopTest(); caesd = [SELECT RAESD_Status__c FROM Consum_Apply_Equipment_Set_Detail__c]; System.assertEquals('已分配',caesd.RAESD_Status__c); } static testMethod void testSave() { ConsumTestDataFactory factory = new ConsumTestDataFactory(); factory.setupTestData(); factory.selectDetails(); factory.approve(); factory.defaultAssign(); Consum_Apply_Equipment_Set_Detail__c caesd = [SELECT Id, RAESD_Status__c, Consum_Apply_Equipment_Set__c FROM Consum_Apply_Equipment_Set_Detail__c]; System.assertEquals('已分配', caesd.RAESD_Status__c); PageReference ref = new PageReference('/apex/ConsumSelect?recid=' + caesd.Consum_Apply_Equipment_Set__c); Test.setCurrentPage(ref); ConsumSelectController controller = new ConsumSelectController(); CreateRelationListPagingCmpCtrl cmp = new CreateRelationListPagingCmpCtrl(); cmp.pageController = controller; controller.myComponentController.init(); controller.init(); controller.searchOpp(); System.assertEquals(1, controller.viewList.size()); Test.startTest(); controller.viewList[0].check = true; caesd = (Consum_Apply_Equipment_Set_Detail__c) controller.viewList[0].sobj; caesd.Fen_Pei_Shu_Liang_Jia__c = 0; controller.save(); Test.stopTest(); // 一览下全都已分配的话,就不能取消分配 caesd = [SELECT RAESD_Status__c FROM Consum_Apply_Equipment_Set_Detail__c]; System.assertEquals('已分配',caesd.RAESD_Status__c); } static testMethod void testCoverUp() { ConsumSelectController.test(); } }