@AuraEnabled
public static Integer generateRandomString() {
try{
return Math.round((Math.random() * (900000) + 100000));
}
catch (Exception e)
{
throw e;
}
}
1 Answer
Do some final polishing of your method. Do you want to call your method something with String, when it returns an Integer? Do you need an error handler? Which of the brackets do you really need?
Implement the hull of your test class. Something like this:
@IsTest
private class CalculatorTest {
@IsTest
private static void generateRandomString() {
Test.startTest();
// TODO 1
Test.stopTest();
// TODO 2
System.assert(true);
}
@TestSetup
private static void testSetup() {
}
}
Ponder if you need anything in preparation of the test of your method. Does the database need to be set up? Do you need to know something about your environment, like record types, custom metadata types etc? In your case, - probably not.
Call your method below TODO 1. Make sure you save the returned value to a variable.
We are almost there. Think of the range of the output of your method. Think what you can be sure of. Do you expect values smaller than 0? Do you expect a million? Even something bigger? Change the "true" under TODO 2 to one of these cases. Compare the variable with -1, 1 000 000, something of your choice.
Create copies of the test method generateRandomString(), each testing a different aspect of your returned value.
:-)
-
1
generateRandomString()
when it returns an integer....