I got this error when i save my test class:

Error: Compile Error: Constructor not defined: [ApexPages.StandardController].<Constructor>() 


public class ContentVersionAlt {
private List<ContentVersion> ContentVersions;
public string host{get;set;}

    public ContentVersionAlt(ApexPages.StandardController controller) {

    public List<ContentVersion> getContentVersions() {

    ContentVersions= [Select c.id ,c.Software_Download__c,c.title,c.description,c.FileType From ContentVersion c where c.Software_Download__c=:System.currentPagereference().getParameters().get('id')];
        return ContentVersions;



private class ContentVersionAltTest {
 static testMethod void ContentVersionsTest(){

          PageReference pageRef = Page.SoftwareDownloadFiles;

        ApexPages.StandardController sc = new ApexPages.standardController();
        //create an instance of the controller
        ContentVersionAlt myPageCon = new ContentVersionAlt(sc);

         ContentVersion testContentInsert =new ContentVersion(); 
         testContentInsert.Title ='Google.com'; 

         insert testContentInsert;   

         ContentVersion testContent = [SELECT ContentDocumentId FROM ContentVersion where Id = :testContentInsert.Id]; 

         ContentWorkspace testWorkspace = [SELECT Id FROM ContentWorkspace WHERE Name='Opportunity Documents ']; 
         ContentWorkspaceDoc newWorkspaceDoc =new ContentWorkspaceDoc(); 
         newWorkspaceDoc.ContentWorkspaceId = testWorkspace.Id; 
         newWorkspaceDoc.ContentDocumentId = testContent.ContentDocumentId; 
         insert newWorkspaceDoc;

         update testContent; 



How can i solve this?

1 Answer 1


The constructor for ApexPages.StandardController takes an SObject as its argument as in:

ApexPages.StandardController sc = new ApexPages.standardController(testContentInsert);

You will need to create the empty ContentVersion SObject (if testing an insert use case) or insert the ContentVersion SObject (if testing an update use case) before instantiating the StandardController. If you want to do both use cases in the same testmethod, you will need to instantiate different StandardController instances

  • Thanks this helped me solve a problem I was having writing unit tests. Oct 16, 2014 at 21:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .