You need to sign in to do that
Don't have an account?

Apex Class: lines not being tested
I'm currently trying to add this Apex class: public with sharing class FileUploadController { public Document document { get { if (document == null) document = new Document(); return document; } set; } public PageReference upload() { document.AuthorId = UserInfo.getUserId(); document.FolderId = UserInfo.getUserId(); // put it in running user's folder try { insert document; }catch (DMLException e) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file')); return null; }finally { document.body = null; // clears the viewstate document = new Document(); } ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully')); return null; } }
When I try to test the class, it will say that it's skipped 17 of the 27 lines. I'm obviously a little new to this. What could I have done wrong? |
It sounds like you don't have any test code included in your class. In order to get test code coverage you'll need to write a testmethod that specifically runs you're class.
the test method can be included right within your FileUploadController class and would look something like this.
Paste the above code into your class and re-run unit tests. You should have coverage once the test method is in place.
All Answers
Can you share the test code you're using to test the class? ...and are you able to see which lines of code aren't getting covered?
I'm currently using Force IDE, so it's the test that comes with that from what I can understand.
Yes it gives a list of them in the error code: lines: 1,3,5,6,7,11,12,13,15,16,17,18,19,21,22,24,25
I tried it once more. I basically started from scratch using: http://developer.force.com/cookbook/recipe/uploading-a-document-using-visualforce-and-a-custom-controller as a guide. It gives me another error now. FileUploadController:file name mismatch with class name: FileUploadController.
Where FileUploadController is the name of the class.
It sounds like you don't have any test code included in your class. In order to get test code coverage you'll need to write a testmethod that specifically runs you're class.
the test method can be included right within your FileUploadController class and would look something like this.
Paste the above code into your class and re-run unit tests. You should have coverage once the test method is in place.