When testing your Apex classes, you should be testing actually functionality not just adding asserts in for no reason. I'd recommend looking at the Apex Testing Trailhead module to help explain some of the reasons for this.
At a minimum your test class should be expanded to:
Have multiple scenarios. At the very least you should have a test method in which there are Cases for retrieval and one where there is not. This ensures that you're actually testing the various scenarios your code will encounter.
Construct data in a TestSetup method to help create the data that is required for your scenarios.
Asserts should actually test what is returned from your code versus what you are expecting to happen. In this case, you should know how many cases are assigned to the user that is calling the method in your test and use System.assertEquals
to ensure that what you are expecting has occurred. This ensures that you are testing the logic of your class not just the fact that it can run.
A pseudocoded example of what your test method could look like if you take these into account looks something like this:
@IsTest
public class ActualCasesAPEXControllerTest{
@TestSetup
static void setupTestData(){
// Create Users for each scenario (where they should be distinct)
List<User> testUsers = new List<User>();
// Create User who will own cases and User who will not own cases
// Insert Test Users
insert testUsers();
List<Case> testCases = new List<Case>();
// Create the cases you need to test with,
// ensuring you assign them to the correct test user
}
@isTest
public static void testUserWithCases(){
//Get the approrpiate test user
System.runAs(testUser){
//Call the method
Decimal numberOfCases =
ActualCasesAPEXController.getActualCases();
/* Now use assert to actually test the result.
You know how many cases you're expecting, so
you need to assert what was returned.*/
System.assertEquals(expectedNumberOfCases,
numberOfCases,
'The User should have x number of cases assigned.');
}
}
@isTest
public static void testUserWithoutCases(){
//Get the approrpiate test user
System.runAs(testUser){
//Call the method
Decimal numberOfCases =
ActualCasesAPEXController.getActualCases();
/* Now use assert to actually test the result.
You know how many cases you're expecting,
so you need to assert what was returned. */
System.assertEquals(0, numberOfCases,
'The User should have no of cases assigned.');
}
}
}
Note: Although you are asking about using System.assert/assertEquals/assertNotEquals in your question, Salesforce recommends to use the newer Assert Class.