1

I am trying to learn how to do APEX testing but all the tests in the documentation are too complex and I can't find an example of a simple APEX Controller that is a Hello World Test.

I have this APEX Code

public class MessageMaker{
public static string helloMessage() {
    return('You say "Goodbye," I say "Hello"');
    }
}

Should I be testing that the String is the same? Here is my test that doesn't work

    @isTest
public class MessageMakerTest {
    public static testMethod void testMyClass(){

       MessageMaker controller = new MessageMaker();
        String helloMessage = helloMessage();

        System.assertEquals(helloMessage, 'You say "Goodbye," I say "Hello"');

    }
}

I am getting this error.

Method does not exist or incorrect signature: helloMessage()

I have some more advanced APEX code but I want to understand what I need to test for and how before I can do that. Thank you in advance.

3

You declared helloMessage() method as static.

In your test class, instead of instantiating MessageMaker just refer to the method as MessageMaker.helloMessage();

@isTest
public class MessageMakerTest {

   public static testMethod void testMyClass(){
       String helloMessage = MessageMaker.helloMessage();

       System.assertEquals(helloMessage, 'You say "Goodbye," I say "Hello"');

   }
}
| improve this answer | |
  • 100% Code coverage! Thank you Kurusu! – proteuscanvas Jul 27 '14 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.