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.

1 Answer 1

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"');

   }
}
1
  • 100% Code coverage! Thank you Kurusu! Jul 27, 2014 at 4:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .