@isTest private class NewRepairPartsControllerTest { static testMethod void testMethod1() { List rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE']; List rectOpp = [select Id from RecordType where IsActive = true and SobjectType = 'Opportunity' and Name = 'SSBD']; Id pricebookId = Test.getStandardPricebookId(); Pricebook2 pricebook = new Pricebook2( Name = 'IE', ProductSegment__c = 'IE', TradeType__c = 'Taxation', SalesChannel__c = 'direct', MachineParts__c = 'Machine', CurrencyIsoCode = 'CNY' ); insert pricebook; Product2 product1 = new Product2(); product1.Name = 'product1'; product1.IsActive = true; product1.ProductCode = 'product1'; product1.ProductStatus__c = '1'; product1.NMPAStatus_one__c = 'Z1'; product1.MaterialStatus_one_Start__c = Date.today().addDays(-22); product1.MaterialStatus_one_End__c = Date.today().addDays(22); insert product1; SWO__c swo = new SWO__c(); swo.Name = 'Test'; insert swo; PageReference page = new PageReference('/apex/NewRepairParts?swoId=' + swo.Id + '&id='); System.Test.setCurrentPage(page); NewRepairPartsController controller = new NewRepairPartsController(); controller.init(); controller.repairPart.Product__c = product1.Id; controller.repairPart.QUANTITY__c = 1; controller.repairPart.LOCATION__c = 'Beijing'; controller.deleteAction(); controller.save(); RepairPart__c repairPart = new RepairPart__c(); repairPart.SWO_ID__c = swo.Id; insert repairPart; PageReference page1 = new PageReference('apex/NewRepairParts?swoId='+swo.Id+'&id='+repairPart.Id); System.Test.setCurrentPage(page1); NewRepairPartsController controller1 = new NewRepairPartsController(); controller1.init(); controller1.deleteAction(); controller1.mastData(); } }