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
Eager-2-LearnEager-2-Learn 

Test script has 0% coverage!

HI,

 

I am scratching my head hard on this one.  What seemed very simple -- I get zero coverage!  Does anyone have an idea what I am doing wrong?  Thanks

@isTEST
private class Utils_TEST {
    static testMethod void test_1() {        
        User currentUser = new User();
        currentUser = [ Select email, Name , id from User where username = :UserInfo.getUserName() limit 1 ];        
        List<String> toAddresses = new List<String> {currentUser.Email};
        String replyToAddress = currentUser.Email;  
        Test.StartTest();      
        Utils.EmailUtil email = new Utils.EmailUtil(toAddresses);
        email.plainTextBody('Utils.EmailUtil Test');
        email.htmlBody('Utils.EmailUtil Test');
        email.senderDisplayName(currentUser.Name);
        email.subject('Utils.EmailUtil Test');
        email.replyTo(replyToAddress);
        email.bccAddresses(toAddresses);
        email.sendEmail();
        Test.StopTest();
    }
}

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ChizChiz

From your explanation I can recomend to you to check test classes on errors. If there is an error it will stop executign other tests.

Just check if there is any error.

All Answers

ChizChiz

Why do you think it's 0%? Where do you look this digit?

And there are no exceptions?

Eager-2-LearnEager-2-Learn

Thanks for responding.

 

It says Code Coverage Total %0 at the top (over all is what I think this is) and it says it at the class level Utils 76 this morning but last night it had zero in both areas--I swear to you!!!! :)  Any way -- in regard to the asserts -- I try to get as much code coverage as I can first then  work on asserts because I am struggling just to get code coverage.  I spend more time on writing test scripts than the actual code! But I am sure I am not alone.  Although I am slowly getting better -- I get road blocks left and right.

 

In fact, I have another post I am going to send out about trying to write a test script for code that needs about 300 different users to be assigned to 300 opportunities.  My if statement is going to require this.  Any way if you see that post and can help I would appreciate it.

 

Thanks again!

ChizChiz

From your explanation I can recomend to you to check test classes on errors. If there is an error it will stop executign other tests.

Just check if there is any error.

This was selected as the best answer
Eager-2-LearnEager-2-Learn

Now that you said that -- that explains it.  I was getting an error.  Here is what I did.  I added that new function that you can add in your code (not test class) that checks if a test is running.  I added this in my if statement that checks for 249 users on a single email toAddress (Mass email only allows 250 max).  In DEV I don't have that much existing data so it wasn't an issue but when I moved the code to TEST (Full Sandbox) the existing data exposed an error and that was were I saw the zero coverage.  You are the wise one Chiz or should I say Wize! :)

 

I am tryiing to write a loop now that will create 300 users and opportunities so that I can test this code properly.  If I get stuff I will start a new post because I am sure others may have similiar issues like this. 

ChizChiz

I'm not that wise. I just had that same issue an hour ago :smileywink:

Eager-2-LearnEager-2-Learn

My father always said:

A smart man learns from his mistakes but a wise man learns from other peoples mistakes so you are the smart man and I am the wise man! LOL -- just jokes.

VJSFDCVJSFDC

hi,

 

Even i get his issue of 0% Coverage when i Run a Test Script.

Since i am learner  of SFDC,some times i write test script to check whether my Logic will work out or not.

I find the same issue but when i check the Log it does not show me any errors.

is this is how SFDC works ?

 

Thanks.

Eager-2-LearnEager-2-Learn

Try using the 'Apex Test Execution feature.  I believe when I tested a few of my scripts there it showed one of the classes that had an issue even thought it seemed to not sure when I run the test from the Apex Classes link.

 

Then I was able to track the issue down

ChizChiz

Where are you perform tests? In browser or in IDE?

VJSFDCVJSFDC

hi,

 

In the browser not the IDE tool.

ChizChiz

Sorry,

I don't konw how to help you.

Can you post example of your class and test class which have to test your "working" class?

Eager-2-LearnEager-2-Learn

When you click the TEST button at the top of the test class area and the results come back are you scrolling down looking for your class that the test class is testing and reviewing that coverage percentage? 

 

I know that you have he same issue as I did but it may be best that you start a new questions since I marked this one as answered.  Then we can start fresh with your questions because if your solution is different than mine you will not be able to mark it as answered and that may not help those researching for solutions.