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
Eric_ArizonaEric_Arizona 

how can you test a class of utility methods that simply pass parms back and forth?

How do you create a test class over a utility class when the methods are pretty much all just passing parms back and forth? For example I have a method that gets passed a name field and the method just does some formatting like first letter upper case the rest of each word lower case, etc.  finally it passes the name back.
Since tests are all static.  
Thanks for the help.
Best Answer chosen by Eric_Arizona
GunnarGunnar
@istest
class MyClass_Test {

   static testmethod void myTestMethod() {

   Test.startTest();

   myClass mc = new myClass();
   string sIShouldGetThis;
   string sIGotThat;

   sIShouldGetThis = '123'
   sIGotThat       = mc.MyMethod();

   // repeat the above for every method in the class.

   Test.stopTest();

   System.assertEquals(sIShouldGetThis, sIGotThat);

   }
}

All Answers

GunnarGunnar
@istest
class MyClass_Test {

   static testmethod void myTestMethod() {

   Test.startTest();

   myClass mc = new myClass();
   string sIShouldGetThis;
   string sIGotThat;

   sIShouldGetThis = '123'
   sIGotThat       = mc.MyMethod();

   // repeat the above for every method in the class.

   Test.stopTest();

   System.assertEquals(sIShouldGetThis, sIGotThat);

   }
}
This was selected as the best answer
Eric_ArizonaEric_Arizona
that makes sence except for one thing...
how do I get my beginning varialbe sHereIsWhatIHave passed into my test method
GunnarGunnar
You don't pass things into the test method. Everything happens in the test method.
In the example, the method in the program does not take parameters. It just give some value.

If you need ot pass a variable into the method in your program - then make one up and pass it in.

Then compare what you get with what you think - this done in the assert.
Eric_ArizonaEric_Arizona
Finally I got it !
Thanks so much for the help


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@isTest
class RciService_Test{

        static testMethod void vldt_capitalizeFirstLetters(){

        Test.startTest();

        string sThisIsWhatIHave = 'FIRST name o\'maLLY';
        string sIShouldGetThis;
        string sIGotThat;

        sIShouldGetThis = 'First Name O\'Mally';
        sIGotThat       = RciService.capitalizeFirstLetters(sThisIsWhatIHave);
       
        System.debug('this-' + sIshouldGetThis + ' and That-' + sIGotThat);
   
       Test.stopTest();
       
        System.assertEquals(sIShouldGetThis, sIGotThat);

    }

}

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++