You need to sign in to do that
Don't have an account?
RoyMoore
Trailhead - Getting Started with Apex Unit Tests - TemperatureConverter example...
At the end of the TemperatureConverter example, it says...
"After you run tests, code coverage is automatically generated for the Apex classes and triggers in the org. You can check the code coverage percentage in the Tests tab of the Developer Console. In this example, the class you’ve just tested, the TemperatureConverter class, has 100% coverage as shown in this image."
And it shows an image of 100% 3/3.
However, my code coverage still says 0% & 0/3 even though I was able to successfully replicate the example and had a good TestRun
Any clues as to why that might be?
"After you run tests, code coverage is automatically generated for the Apex classes and triggers in the org. You can check the code coverage percentage in the Tests tab of the Developer Console. In this example, the class you’ve just tested, the TemperatureConverter class, has 100% coverage as shown in this image."
And it shows an image of 100% 3/3.
However, my code coverage still says 0% & 0/3 even though I was able to successfully replicate the example and had a good TestRun
Any clues as to why that might be?
- Go to Setup->Develop->Apex Test Execution
- Click the "View Test History" link (not button)
- Click the "Clear Test History" button.
- Re run the tests and view the code coverage.
Sometimes the code coverage calculation is buggy, and this helps fix it.However, it looks like your code should be working fine. Have you tried checking your Trailhead challenge to see if you passed?
All Answers
Can you please post the test class for the TemperatureConverter example here? While doing so, please use the code format (< >) button. Thanks!
The above code does cover the class, and test coverage will be 100%. Just click on compile test class and then click the estimate organization's code coverage. Hope it will show the exact code coverage
- Go to Setup->Develop->Apex Test Execution
- Click the "View Test History" link (not button)
- Click the "Clear Test History" button.
- Re run the tests and view the code coverage.
Sometimes the code coverage calculation is buggy, and this helps fix it.However, it looks like your code should be working fine. Have you tried checking your Trailhead challenge to see if you passed?
I tried what you said, but still no love.
As for the challenge, I haven't gotten there yet. this is just the pre challenge educational stuff, but I would like to see it working as intended before moving on.
Roy
I cleared the test data from the developer console and that did the trick. Thanks for pointing me in the right direction.
There are a few different ways of running unit tests. Looks like you're running them from the dev console currently, but you could also
- Open the test class (Setup->Develop->Apex Classes), and click the "Run Test" button.
- Install MavensMate (a Sublime Text 3 plugin that developers use) and use the Execute Apex Tests feature.
I would recommend trying one of those options to see if they report code coverage correctly. Your test class looks good to me and it looks like you should receive 100% (or near) code coverageThere's an issue with the develper console right now not updating the code coverage correctly when running individual tests. We are trying to get the instructions changed in our next release.
In the mean time, I think if you do Test -> Run All that should fix the issue.
Thanks
Jeff Douglas
Trailhead Developer Advocate
Winter '16 - In Developer Console, running tests synchronously does not generate code coverage (https://success.salesforce.com/issues_view?id=a1p30000000eMoyAAE)
Apparently there is a problem with Developer Console in Winter '16 failing to update the code coverage. You can avoid this problem by going into developer console and enabling "Always Run Asynchronously". Alternatively, you can (from settings)
"Develop->Apex Classes->TestVerifyDate->Run Test".
Then check coverage on the class ("VerifyDate"). Hope this helps, and select "Answer" if it solved your problem.