In order to create a Test Class for the following Controller Extension do I need to:

Create an Account
Create an Article or Articles
Create a Case on the Account
Attach an Article to the Case
Load a page using a PageReference with a Case Id in order to test the getId

public class CaseArticlesExtension {   
    public Id RecordId { get; set; }

    public CaseArticlesExtension(ApexPages.StandardController stdController) {
    RecordId = stdController.getId();

public KnowledgeArticleVersion[] getArticles() {

    CaseArticle[] caseArticles = [SELECT KnowledgeArticleId FROM CaseArticle WHERE CaseId = :RecordId];

    list<Id> kaIds = new List<Id>();

    for (CaseArticle art: caseArticles) {

    KnowledgeArticleVersion[] Articles = [SELECT UrlName, Title, Summary, ArticleType 
        FROM KnowledgeArticleVersion 
        WHERE PublishStatus= 'Online' 
        AND Language = 'en_US'
        AND KnowledgeArticleId IN :kaIds];

    return Articles;
  • 1
    That would definitely be my course of action. Yes to all of the above – Antonio Manente Apr 20 '16 at 17:26
  • 1
    @AntonioManente make your comment an answer and I can select it as the best answer. I am creating a new question regarding my test class. – Jason Apr 20 '16 at 20:45
  • Here is my question regarding my attempt at a Test Class salesforce.stackexchange.com/questions/118778/… – Jason Apr 20 '16 at 20:56

I would say yes to all of the above. Apex testing best practice dictates that you should recreate all data necessary to the code's execution to ensure correct behavior as noted in the documentation here.

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.