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
karthikarthi 

can we cover this boolean property should render=true and should render=false in test class?

public Boolean shouldRender{get;set;}

if (loc == 'Visibility') {
    shouldRender = false;
  } else if(loc == 'Ownership'){
    shouldRender = true;
  }

b-Forceb-Force

yes it is possible,

In your test class  define two different test methods 

set loc variable 'Visibility ' and 'OwnerShip'  in two different scenario,

you need to create two scenario here

 

Thanks,

Bala

karthikarthi

how to declare that loc variable in test class

Pradeep_NavatarPradeep_Navatar

Write two test methods in your test class and assign loc = 'Visibility' in one method and loc = 'OwnerShip' in another one.

 

 

 

bob_buzzardbob_buzzard

You wouldn't declare the loc variable in the test class, as you need to set the value of the loc variable in the class that you are testing.

 

Its a little tricky to tell without seeing your entire class, but assuming that the code you have posted is part of a method similar to that shown below:

 

 

public class MyClass
{
   public Boolean shouldRender{get;set;}
   public String loc {get; set;}

   public void determineShouldRender()
   {
      if (loc == 'Visibility') 
      {
         shouldRender = false;
      } 
      else if(loc == 'Ownership')
      {
         shouldRender = true;
      }
   }
}

 

 

You'll need a test something like this:

 

 

public static testMethod void testShouldRender()
{
   MyClass cand=new MyClass();
   cand.loc='Visibility';
   cand.determineShouldRender();
   System.assertEquals(true, cand.shouldRender);  

   MyClass cand2=new MyClass();
   cand2.loc='Ownership';
   cand2.determineShouldRender();
   System.assertEquals(true, cand2.shouldRender);  
}

 

 

 

 

sfdcfoxsfdcfox

Bob,

 

Click on the poster's user name; they have several posts in regards to this class they're attempting to get working, a whole handful of them. I commented on one, and that one has the full class. Maybe you can help out further.

Pradeep_NavatarPradeep_Navatar

Tryout the below sample code :

 

                                                 @isTest

                                                private class TestVolunteerRegistration

                                                {

                                                                static testMethod void testRunAs1()

                                                                {

                                                                sa_volunteer_registration VolReg = new sa_volunteer_registration();

                                                                // You can cover the loc = "visbility" here....

                                                                }

                                                                static testMethod void testRunAs2()

                                                                {

                                                                sa_volunteer_registration VolReg = new sa_volunteer_registration();

                                                                // you can cover the loc = "Ownership" here...

                                                                }

                                    }

 

Hope this helps.