4

I am having some trouble getting any code coverage from my Test class. I noticed on the forum that there seemed to be an issue in regards to inner classes, which led me to a similar issue below:

A Similar Issue

However, I am using an inner abstract class and with that abstract class, extending it and creating a concrete class. Once I run my test, it gives me Zero % code coverage. Needless to say, this is quite an agitating issue.

Diagnostic Code


public with sharing class DiagnosticsInstrumentation 
{
    public abstract class BaseDiagnostics
    {
        private Boolean DiagnosticsEnabled;

        private List DiagnosticLog;

        public abstract void Push(String FunctionName);
        public abstract void Pop();
        public abstract void PopAll();
        public abstract void DiagnoseException(Exception DiagnosedException);

        private abstract String CurrentLog();
        private abstract void Diagnose(String DaignosticStatement);
        private abstract Boolean IsEnabled();

        public BaseDiagnostics()
        {
            this.DiagnosticsEnabled = this.IsEnabled();
            this.DiagnosticLog = new List();
        }
    }

    public class DiagnosticEntry
    {
        //...

        public DiagnosticEntry(String EntryDescription, Integer LevelNumber)
        {
            //...
        }
    }

    public class BasicDiagnostics extends BaseDiagnostics
    {
        public override void Push(String FunctionName)
        {
            //...
        }

        public override void Pop()
        {
            //...
        }

        public override void PopAll()
        {
            //...
        }

        public override void DiagnoseException(Exception DiagnosedException)
        {
            //...
        }

        private override String CurrentLog()
        {
            //...

            return null;
        }

        private override void Diagnose(String DiagnosticStatement)
        {
            //...
        }

        private override Boolean IsEnabled()
        {
            return true;
        }
    }
}

The Diagnostic Code's Test Class
Note: In the test I added the static part but, if you add or remove it it makes no difference.


@isTest
public with sharing class BasicDiagnostics_Tests 
{
    static 
    {
        new DiagnosticsInstrumentation();
    }

    public static TestMethod void Test_BasicDiagnostics_Functionality()
    {
        DiagnosticsInstrumentation.BaseDiagnostics TestDiagnosticTool = new DiagnosticsInstrumentation.BasicDiagnostics();

        TestDiagnosticTool.Push('Testing One Input');
        TestDiagnosticTool.Pop();

        TestDiagnosticTool.Push('Testing Two Input');
        TestDiagnosticTool.Push('Testing Three Input');
        TestDiagnosticTool.Push('Testing Four Input');

        TestDiagnosticTool.PopAll();

        Account NullAccount = new Account();

        try
        {
            INSERT NullAccount;
        }
        catch(DmlException Caught)
        {
            TestDiagnosticTool.DiagnoseException(Caught);
            TestDiagnosticTool.PopAll();
        }
    }
}

I thank anyone in advance for your help on this issue.

  • How are you running the tests? Sometimes I've seen a 0% after running, and then I just run again and it magically appears. I think there's some caching of results that can get a bit messed up from time to time. – Matt Lacey Jun 12 '13 at 0:45
  • I have run the test multiple times in the Eclipse IDE with the Force.com Plug-in, Developer Console, and through the setup menu. All still produce zero code coverage. – Programmable Medley Jun 12 '13 at 1:00
  • 1
    I'm thinking it could be related to the abstract class that's being used. If you add a constructor to BasicDiagnostics does that get covered? – Matt Lacey Jun 12 '13 at 1:02
  • I went ahead and tried that - still no results :-\ ... – Programmable Medley Jun 12 '13 at 1:14
3

Okay, oddly enough, adding the constructor to the base class was the trick to having the Test class pass. However, it didn't pass until I ran it through the setup menu. ::shurgs:: Such a simple answer to a stubborn problem.

  • For some reason, although the code coverage is being met (finally), it only works when you run it through the setup menu. It does not give any code coverage through the Eclipse IDE or the Developer Console. Just keeping that in mind. – Programmable Medley Jun 13 '13 at 17:18
  • Big Update : Today I was running my tests through the IDE and it showed that it covered my classes within the Code Coverage window. I also removed the empty constructor and it still worked! I suppose enough people either complained or someone was listening ::looks around::. – Programmable Medley Jun 24 '13 at 21:05

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.