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
vasu takasivasu takasi 

how to get a particular variable from a method for writting test method

hi i have code like

public class abc

{

string s1='picklist';

string s2;

string s3;

public void m1()

{

if(s1=='picklist')

{

//some code here
}

else if(s1=='text')

{

//------------

}

}

in text method how to pass s1 value ?;

 

please help me.

Baktash H.Baktash H.

public void m1(String parameter){

if(s = 'picklist') System.Debug('Hello');

}

 

You have to call the function like this:

m1(yourString);

 

the string you pass will be the parameter the function gets.

Starz26Starz26

public static testmoethod void testClass(){

 

  abd a = New abc();

 

  a.S1 = 'picklist';

  a.m1();  

   //Then test for results here

 

  a.S1 = 'text';

   a.m1();

  //Test for results here

 

}

 

You instantiate the class, then set the variables, then execute your method as above