[英]APEX Test Class 0% code coverage
I am trying to deploy some code that does something simple, when the user clicks on the accept button, it checks a checkbox (I have a workflow set up on the checkbox) and then I need it to redirect me to a thank you page. 我正在尝试部署一些简单的代码,当用户单击“接受”按钮时,它会选中一个复选框(我在该复选框上设置了工作流程),然后需要它将我重定向到“谢谢”页面。 At the moment I don't know if my code is correct so I need to get the test correct to test it.
目前,我不知道我的代码是否正确,因此我需要获得正确的测试才能对其进行测试。
My Apex
class: 我的
Apex
课程:
public class proposalCon {
ApexPages.StandardController stdCtrl;
Public List <PPM_Project__c> PPM_Project_List {get;set;}
public proposalCon(ApexPages.StandardController controller) {
stdCtrl= controller;
PPM_Project_List = [ select Short_Description__c from PPM_Project__c ];
}
public PageReference save(){
upsert PPM_Project_List;
PageReference reRend = new PageReference('/apex/final_approval_canvas_complete');
reRend.setRedirect(true);
return reRend;
}
}
And here is my test attempt: 这是我的测试尝试:
@isTest
private class proposalConTest{
static testMethod void testProposalCon() {
// List of Message
List <PPM_Project__c> PPM_ProjectList = new List<PPM_Project__c>();
PPM_ProjectList.add(new PPM_Project__c (
Name = 'A Test' ,
Short_Description__c = 'Good Job',
Due_Date__c = system.today()+30,
Final_Design_Artwork__c ='http://proteusleadership.com/DE123'
));
PPM_ProjectList.add(new PPM_Project__c (
Name = 'A Test 2' ,
Short_Description__c = 'Good Job',
Due_Date__c = system.today()+30,
Final_Design_Artwork__c ='http://proteusleadership.com/DEf123'
));
insert PPM_ProjectList;
Account account = new Account(Name='Test Co Pty Ltd');
insert account;
Contact contact = new Contact(firstName='TestFN',LastName='TestLN',email='testfn.testln@test.com',AccountId=account.Id);
insert contact;
// ** Start Testing ***/
proposalCon controller = new proposalCon();
PageReference reRend = new PageReference('/apex/final_approval_canvas_complete');
reRend.setRedirect(true);
PPM_ProjectList = [ select Short_Description__c from PPM_Project__c ];
}
}
I have been trying with no luck and any help would be greatly appreciated. 我一直没有运气,任何帮助将不胜感激。
Thank you. 谢谢。
Joe 乔
You need to instantiate a Standard Controller (feeding it a list of PPM Projects) and then instantiate your custom controller extension - like this: 您需要实例化一个标准控制器(向其提供PPM项目列表),然后实例化您的自定义控制器扩展-像这样:
PPM_Project__c proj = new PPM_Project__c() //you may need further parameters here.
ApexPages.StandardController stdController = new apexPages.StandardController(proj);
proposalCon controller = new proposalCon (stdController);
Then you can save, rerender as you like. 然后,您可以保存,重新渲染。 Let me know if this works - I haven't executed this code, but this is how I create my own controller extension tests.
让我知道这是否有效-我尚未执行此代码,但这是我创建自己的控制器扩展测试的方式。
This should at least compile. 这至少应该编译。 However, I think you may really want a StandardSetController.
但是,我认为您可能真的想要StandardSetController。 The docs are here: SalesforceDocs
文档在这里: SalesforceDocs
To make a testmethod for the StandardSetController, use something like this: 要为StandardSetController制定测试方法,请使用以下方法:
//instantiate the ApexPages.StandardSetController with an array of projects
ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(PPM_ProjectList);
//create custom controller with the StandardSetController as a param
ProposalCon ext = new ProposalCon(stdSetController);
This guy has more details on how to create a test method for a StandardSetController (and other controllers) 这个家伙有更多有关如何为StandardSetController(和其他控制器)创建测试方法的详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.