First, you should know that your getters and setters themselves are methods. Just because you're using shorthand syntax doesn't change the fact that you're implicitly creating methods.
/**
* Convenient getter and setter method definition
* using Apex in Salesforce
*/
public class PlainOldApexObject {
public String name { get; set; }
}
/**
* Java equivalent, showing what the Apex shorthand
* is effectively doing
*/
public class PlainOldJavaObject {
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
Second, any code you create must be used somewhere to add value to something. Otherwise the code is worthless, and you should just delete the code.
So, since your code is used somewhere to facilitate some business process, by virtue of fully testing the relevant business process, your simple class should've been covered 100% already, without you having to write any Apex tests just for the simple class.
Example: Lightning Component Model
Since you showed the @AuraEnabled
annotation in your sample code, I'm assuming you're probably trying to cover an Apex model you'd created for a Lightning component or app. As with Visualforce, the most basic test here is to simulate the loading of a page/view in your Apex test.
Let's say you have the following controller, no action methods, just properties.
public class ExpenseTrackerController {
@AuraEnabled
public Date currentDate { get; set; }
@AuraEnabled
public String summary { get; set; }
}
And this controller is used to back an Expense Tracker app. In this case, you may write Apex tests as follows, which not only provides code coverage but also validates the expected use of that code in a real scenario.
/**
* Tests to cover the controller and model behaviors supporting the Expense
* Tracker app (expenseTracker.app). Assume there's an Apex class backing
* the app called ExpenseTrackerController.
*/
@isTest
private class ExpenseTrackerAppTest {
/**
* Test that the user is able to log an expense in the app
*/
@isTest
private static void userLogsExpense {
// Initialization of the controller
ExpenseTrackerController controller = new ExpenseTrackerController();
// Simulate the load of the controller specifically in the context
// of the Expense Tracker app
loadExpenseTrackerApp(controller);
// Start the test and enter some data
Test.startTest();
// Simulate data entry
controller.currentDate = Date.today(); // invokes setter
controller.summary = 'Apex testing Q&A'; // invokes setter
// ...
}
/**
* Utility method used by all test methods to simulate the initial loading
* of the Expense Tracker app. When the app loads, all getters are called
* to get the values of specific properties in the controller.
*/
private static void loadExpenseTrackerApp(
ExpenseTrackerController controller) {
// Simulate the getting of specific properties, in the order that
// they are rendered on the view.
Date currentDate = controller.currentDate; // invokes getter method
String summary = controller.summary; // invokes getter method
}
}