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
ursmahiursmahi 

i am unable to cover Testclass please give me a suggestion to do

public class mainreports_class {
list<selectoption> v=new list<selectoption>();
public list<selectoption>getGetvalues() {
v.add(new selectoption('Select','--Select Rport--'));
v.add(new selectoption('FR Performance report based on Month','FR Performance report based on Month'));
v.add(new selectoption('MD Order Report','MD Order Report'));
v.add(new selectoption('Region Performance based on CBF','Region Performance based on CBF'));
v.add(new selectoption('Retailer Performance based on Month','Retailer Performance based on Month'));
return v;
}

public String selectedvalue { get; set; }
public String url{ get; set; }
User usr = [Select id,Alias,lastname,ContactId,Profile.name from User where id=:UserInfo.getUserId() Limit 1];
string prof=usr.Profile.name;


public void rpid() {
if(prof=='CMM East Profile')
{
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=East&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=East&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=East&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=East&isdtp=nv';
}

}else if(prof=='CMM South Profile'){
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=South&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=South&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=South&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=South&isdtp=nv';
}

}else if(prof=='CMM North Profile'){
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=North&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=North&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=North&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=North&isdtp=nv';
}

}
else if(prof=='CMM West Profile')
{
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=West&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=West&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=West&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=West&isdtp=nv';
}

}


}



}

 

my test class

@istest(seealldata=true)
public class testmainreports_class
{
User usr = [Select id,Alias,lastname,ContactId,Profile.name from User where id=:UserInfo.getUserId() Limit 1];
string prof=usr.Profile.name;


public static testmethod void test1()
{



mainreports_class c=new mainreports_class();
c.getGetvalues();

 

c.rpid();

}
}

imutsavimutsav

You need to modify your test class something like this.

 

 

my test class

@istest(seealldata=true)
public class testmainreports_class
{

public static testmethod void test1()
{

 

User usr1 = [Select id,Alias,lastname,ContactId,Profile.name from User where profileid.Name=:'CMM East Profile' LIMIT 1];

 

User usr2 = [Select id,Alias,lastname,ContactId,Profile.name from User where profileid.Name=:'CMM South Profile' LIMIT 1];

 

User usr3 = [Select id,Alias,lastname,ContactId,Profile.name from User where profileid.Name=:'CMM North Profile' LIMIT 1];

 


mainreports_class c=new mainreports_class();
c.getGetvalues();

if(usr1!=NULL) {

System.runAs(usr1) {

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Region Performance based on CBF';

     c.rpid();

 

     c.selectedvalue ='MD Order Report';

     c.rpid();

 

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Retailer Performance based on Month';

     c.rpid();

 

}

 

}

if(usr2!=NULL) {

System.runAs(usr2) {

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Region Performance based on CBF';

     c.rpid();

 

     c.selectedvalue ='MD Order Report';

     c.rpid();

 

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Retailer Performance based on Month';

     c.rpid();

 

 }

}

 

if(usr3!=NULL) {

System.runAs(usr3) {

 

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Region Performance based on CBF';

     c.rpid();

 

     c.selectedvalue ='MD Order Report';

     c.rpid();

 

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Retailer Performance based on Month';

     c.rpid();

 

 }

}

 

 

 

}

}

 

Let me know if it helps you. Don't forget to give Kudos on this post if it helps you.

 

Thanks

Utsav

 

 

ursmahiursmahi

i am getting only 34% test coverage boss..........

imutsavimutsav

can you tell me which lines are not getting covered ?

ursmahiursmahi

public void rpid() {
if(prof=='CMM East Profile')
{
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=East&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=East&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=East&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=East&isdtp=nv';
}

}else if(prof=='CMM South Profile'){
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=South&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=South&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=South&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=South&isdtp=nv';
}

}else if(prof=='CMM North Profile'){
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=North&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=North&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=North&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=North&isdtp=nv';
}

}
else if(prof=='CMM West Profile')
{
if(selectedvalue =='FR Performance report based on Month')
{
url='/00Oa0000007nvM7?pv0=West&isdtp=nv';
}else
if(selectedvalue =='MD Order Report')
{
url='/00Oa0000007nvMb?pv0=West&isdtp=nv';
}else
if(selectedvalue =='Region Performance based on CBF')
{
url='/00Oa0000007nvMS?pv0=West&isdtp=nv';
}else
if(selectedvalue =='Retailer Performance based on Month')
{
url='/00Oa0000007nvMH?pv0=West&isdtp=nv';
}

}


}

imutsavimutsav

I see; the problem looks like you don't have any user with these profiles. You need to create four users with all the four profiles and then you have to use these users in your test. 

(Do make sure that these profiles are already created in your org.)

 

 

my test class

@istest(seealldata=true)
public class testmainreports_class
{

public static testmethod void test1()
{

 

List<String> profileNames = new List<String>();

profileNames.add('CMM East Profile');

profileNames.add('CMM South Profile');

profileNames.add('CMM North Profile');

profileNames.add('CMM West Profile');

 

 

List<Profile> profileLists = [select id,Name from profile where Name in :profileNames];

 

User usr1 = new User(alias = 'Tst1', email='testuser1@test.com',
            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
            localesidkey='en_US', profileid = :profileLists.get(0).Id,
            timezonesidkey='America/Los_Angeles', username='testuser1@test.com');
        
User usr2 = new User(alias = 'Tst2', email='testuser2@test.com',
            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
            localesidkey='en_US', profileid = :profileLists.get(1).Id,
            timezonesidkey='America/Los_Angeles', username='testuser2@test.com');

 

User usr3 = new User(alias = 'Tst2', email='testuser3@test.com',
            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
            localesidkey='en_US', profileid = :profileLists.get(2).Id,
            timezonesidkey='America/Los_Angeles', username='testuser3@test.com');

 

User usr4 = new User(alias = 'Tst2', email='testuser4@test.com',
            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
            localesidkey='en_US', profileid = :profileLists.get(3).Id,
            timezonesidkey='America/Los_Angeles', username='testuser4@test.com');

 

and now you can use the same test code .

 

mainreports_class c=new mainreports_class();
c.getGetvalues();

if(usr1!=NULL) {

System.runAs(usr1) {

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Region Performance based on CBF';

     c.rpid();

 

     c.selectedvalue ='MD Order Report';

     c.rpid();

 

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Retailer Performance based on Month';

     c.rpid();

 

}

 

}

if(usr2!=NULL) {

System.runAs(usr2) {

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Region Performance based on CBF';

     c.rpid();

 

     c.selectedvalue ='MD Order Report';

     c.rpid();

 

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Retailer Performance based on Month';

     c.rpid();

 

 }

}

 

if(usr3!=NULL) {

System.runAs(usr3) {

 

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Region Performance based on CBF';

     c.rpid();

 

     c.selectedvalue ='MD Order Report';

     c.rpid();

 

     c.selectedvalue ='FR Performance report based on Month';

     c.rpid();

 

     c.selectedvalue ='Retailer Performance based on Month';

     c.rpid();

 

 }

}

 

 

 

}

}

 

Let me know if it helps you. Don't forget to give Kudos on this post if it helps you.

 

Thanks

Utsav