+ Start a Discussion
badri nath 9badri nath 9 

Please provide a test class i am getting only 80% code coverage?

VFpage:
<apex:page controller="c1" sidebar="false" docType="Html-5.0" id="page1"  tabStyle="account">
<apex:form >
<apex:pageBlock >

<apex:inputText value="{!name}" />
<apex:commandButton value="search" action="{!search}"/>
<apex:pageblocktable value="{!acts}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.id}"/>
<apex:column value="{!a.type}"/>
</apex:pageblocktable>
</apex:pageBlock>

</apex:form>
</apex:page>




controller class:

public with sharing class c1 {
      public String name { get; set; }

    public list<account> acts { get; set; }

    public PageReference search() {
     acts=[select id,type,name from account where name like 'b%'];
        return null;
    }
}
Best Answer chosen by badri nath 9
Devanshu soodDevanshu sood
@istest
public class testsearch {
    @istest
    static void testserach1(){
        Account acc=new Account(name='btest',website = 'https://www.google.com');
        insert acc;
        c1 c=new c1();
        c.search();
        c.name='b';
    }

}

100% code coverage