function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sangeeta.marathe@Futurewise.cosangeeta.marathe@Futurewise.co 

Code Test Coverage

What things should be keep in mind while deploying project or single program from Sandbox to Production environment ?

 

I have created one program & it is executing fine in sandboox environment but it is running in production environment & showing me error of code test coverage is of 15% & it must be atleast 75%.

 

The code is as follow...

<!-- Page: -->
<apex:page controller="sampleCon">
    <apex:form>
        <apex:selectRadio value="{!country}">
            <apex:selectOptions value="{!items}"/>
            </apex:selectRadio><p/>
            <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
     </apex:form>
     <apex:outputPanel id="out">
          <apex:actionstatus id="status" startText="testing..."> 
             <apex:facet name="stop"> 
               <apex:outputPanel> 
                  <p>You have selected:</p> 
                 <apex:outputText value="{!country}"/> 
              </apex:outputPanel> 
            </apex:facet> 
          </apex:actionstatus> 
     </apex:outputPanel> 
</apex:page>
            
/*** Controller ***/
public class sampleCon {
    String country = null;
         
    public PageReference test() {
        return null;
    }
                
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('US','US')); 
        options.add(new SelectOption('CANADA','Canada')); 
        options.add(new SelectOption('MEXICO','Mexico')); return options; 
    }
                   
    public String getCountry() {
        return country;
    }
                    
    public void setCountry(String country) { this.country = country; }
}

 Now there are two files & Controller : SampleCon & other is VFPage : RadioButton...I uploaded both the files from outbound change set of sandbox environment & I deployed it from inbound change set of production environment but getting test coverage & action gets failed.

 

Please help me...

Best Answer chosen by Admin (Salesforce Developers) 
Sonali BhardwajSonali Bhardwaj

You have to write code coverage for your class.

Below link would be useful for you:

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

All Answers

Sonali BhardwajSonali Bhardwaj

You have to write code coverage for your class.

Below link would be useful for you:

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

This was selected as the best answer
sangeeta.marathe@Futurewise.cosangeeta.marathe@Futurewise.co

As i uploaded the program that where I have to write the test() in that program...

Because as i know that test method is generally static method & we can't call any non static method inside static method...

Please code is there so can you help for that bcoz i tried too much from last 2-3 days but nt getting...

Sonali BhardwajSonali Bhardwaj

You need to create a different test class for your class, so no matter of static or non static.

If you want to write a test function in the same class you can write like this:

 

static testMethod void testGetItems(){
        sampleCon obj = new sampleCon ();
        obj.getItems();
    }

 

Although, its not complete, you have to follow test class guidelines to make it complete.

sangeeta.marathe@Futurewise.cosangeeta.marathe@Futurewise.co

Thank you so much too help me...

Actually I was totally stuck here but I got the idea but still have one doubt as I tested all my get method as well as different method which don't have any parameter & if there is any parameteriazed methods are there then how to test that methods...

Like in my code there is one method named setCountry(String country) then how to call it...& I stuck here bcoz it takes values after selection...

Sonali BhardwajSonali Bhardwaj

obj.setCountry('India');

sangeeta.marathe@Futurewise.cosangeeta.marathe@Futurewise.co

Thanks alot sonali...