So I am trying to cover this Chatter Answers Class so I can increase my system's code coverage. The test class runs successfully but the original class is still 0% covered. What do I need to do to make sure the test class covers the original class?

Here is my original class:

public class ChatterAnswers {
    public String createAccount(String firstname, String lastname, Id siteAdminId) {
         Account a = new Account(name = firstname + ' ' + lastname, ownerId = siteAdminId);
         insert a;
         return a.Id;

And here is my test class

public class ChatterAnswersTest 
 @isTest static void testChatterAnswers() 
 Account testAccount = new Account() ;
 testAccount.Name='Joe' + 'Smith' ;
 testAccount.OwnerId= '0050Y000003tTH8QAM';
 System.assertEquals('Joe' + 'Smith', testAccount.Name);
 System.assertEquals('0050Y000003tTH8QAM', testAccount.OwnerId);



I tried calling the original class in the test class but that doesn't seem to be working. Can anyone please help me?

Thank you!

  • 3
    You need to call this class: ChatterAnswers by creating an instance of it inside your unit test: testChatterAnswers( ). And try accessing it's methods via that instance. Then do your System.assert statements inside your unit test.
    – SatyaV
    Oct 8, 2018 at 14:42

1 Answer 1


Your test class ChatterAnswersTest is not really calling the class ChatterAnswers that you intend to test, Instead it's just creating a new account record.

To be able to test the class here, you will need to create an instance of your class and call the methods within that class. Your test class should look something as below:

public class ChatterAnswersTest {
    @isTest static void testChatterAnswers() {
        // construct variables
        // my other code
        ChatterAnswers chatAns = new ChatterAnswers();
        String accountId = chatAns.createAccount(firstName, lastName, adminId);
        // assertion statements

  • 2
    @AlexisScott Just to punctuate the importance, the assertions are what make a unit test valuable. In most situations where the thing you're testing involves DML, you'll want to perform a query (in your test method) to grab fresh data from after the DML has been completed (usually, after your test method calls the method you want to test). The goal here is to verify that you've actually inserted/updated data in Salesforce's back-end data store rather than verify that you correctly set up test data in your test method (though bad test data will generally cause assertions to fail)
    – Derek F
    Oct 8, 2018 at 15:40

You must log in to answer this question.

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