You need to sign in to do that
Don't have an account?

Some Testing Doubts
i am trying to test my Controller .One doubt is in using Test.startTet and Test.stopTest().i am checking every method in separate unit test . for example
static testmethod void testEditApiSettings(){ MirrorTestUtility.getApiSettings(); Test.startTest(); MirrorSettingsController ctrl = new MirrorSettingsController(); ctrl.setEditApiSettings(); Test.stopTest(); System.assert(ctrl.editApiSettings,'Method perform to Show Insert view# Not able to set '); } static testmethod void testDeleteApiSettings(){ MirrorTestUtility.setUpSettings(); Test.startTest(); MirrorSettingsController ctrl = new MirrorSettingsController(); ctrl.deleteUserSettings(); Test.stopTest(); GlassUserApiSettings__c userSettings = GlassUserApiSettings__c.getValues(UserInfo.getUserId()); System.assert(userSettings== null ,'User settings are present ence Method don\'t delete Usetr Settings' ); }
so you can see i create ctrl every time in test.startTest() is this more appropriate or creating it before Test.startTest();
there is a DML exception perhaps that cant come because DML limit is 100 and i am hardly using 2-3 in my controller. i write a function
public PageReference deleteUserSettings(){ try{ delete userSettings; userSettings = GlassUserApiSettings__c.getValues(Userinfo.getUserId()); } catch(System.DmlException e){System.debug(e); } return null; }
how to test this should i remove this try catch block (because exception is not expected)??How to test this catch block please guideline .
If you think you can live without this exception you can remove to increase coverage or add other exceptions which you can generate and catch via code in apex test class to incraese coverage.
hope this answers your query!
regards,