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
ShreyankaShreyanka 

how to include get method in test class

Hi Everyone,
Please help me in writing test class for below code

Thanks in advance!
Apex Code example:

public class Example{
public class myMethod{

//code block

}

public Example getAbc{
return abc;
}

 public pagereference save() {

//code block

}
}
PriyaPriya (Salesforce Developers) 
Hi shreyanka,

Can you please refer to the below link 
https://salesforce.stackexchange.com/questions/152385/test-class-coverage-for-get-method

Hope this is helpful!

Regards,
Ranjan
Ron Van Aken 3Ron Van Aken 3
Hi Shreyanka,

I'm sorry but your code sample makes no sense.

Of course you can name classes, variables, and methods any way you want, but if you want other people to be able to make sense of your code you have to use rational names.  This in particular makes no sense: "public class myMethod{".  Classes contain methods, so naming a class "myMethod" damages understanding.  Your class is not static, so it has to be instantiated to call its methods.

Maybe the following is something like what you meant?
public class Example
{
	private String exampleString;

	public String GetExampleString()
	{
		return exampleString;
	}

	public void SetExampleString(String inputExampleString)
	{
		exampleString = inputExampleString;
	}
}
Your test then could look like this:
@isTest
private class ExampleTest
{
	@isTest
	static void ExampleTest1()
	{
		Example exampleThing = new Example();

		exampleThing.SetExampleString('abc');
		String exampleOutput = exampleThing.SetExampleString();

		System.assert(exampleOutput == 'abc');
	}
}
Hopefully you will find this helpful.  (sorry for complaining about your names)