![](https://trailblazers.salesforce.com/img/userprofile/default_profile_200_v2.png)
1 个回答
After successfully run the test class open developer console and open the same class you can see some part of the code is hilighted with blue and some is with red. Blue part means your test class covered that code and red part means you have to cover that one in test class. If you are writing one test method than at one time you can cover either IF condition or Else condition. You can't cover both if and else for one test method. So go and check the part still covered as red. Create one new method in test class and provide the data which is restricting that red part of the code to be covered. Once you will create the data it will cover rest of the code.Ex: You had written below condition-if(String.isEmpty(EmpName)){ ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please Enter The User Name')); return null; }But in test class you had given- e.Name ='Test' ; So your test class will not cover this if condition it will goto else block. So create one method and blank out e.name(Simply means create whatever data test class needed) it will cover this particular if. Like that you can cover rest of the code.