0

I'm getting a compiler error for this test:

@isTest public class TestDirectMailFilter {

public static testMethod void testMyController() {

Campaign c = new Campaign(); c.Name = 'Jacob for president'; c.Type = 'Direct Mail'; insert c;

ApexPages.StandardController sc = new ApexPages.StandardController(c);
**DirectMailfilter dmf = new DirectMailfilter(sc);**
System.assertEquals(1, dmf.getDmcampaigns().size()); }
}

The bold line is giving me this error:

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

Here is the apex class I am trying to test:

public class DirectMailfilter {
public List<campaign> dmcampaigns {get;private set;} 
public DirectMailfilter(ApexPages.StandardsetController controller) {
         dmcampaigns = [SELECT StartDate, Type, Status, Name 
                     FROM Campaign 
                     WHERE Type = 'Direct Mail'];
     }

}

Seems like it should be simple, but I'm clearly missing something. What is it?

  • 1
    looks like your passing in a standard controller in the test, where in your class you have the constructor set up to take a standardSetController – Chris Duncombe Jan 7 '14 at 18:36
  • 1
    @sfdc_ninja: You should post that as an answer. – Mike Chale Jan 7 '14 at 18:37
  • @MikeChale, just added it, was just glancing through and saw it while test code was running, didn't have time to explain an answer, but now I added it. Thanks – Chris Duncombe Jan 7 '14 at 18:56
4

In your class the constructor is set up to take a StandardSetController

public DirectMailfilter(ApexPages.StandardsetController controller) 

But in your test code, you are passing it a StandardController

ApexPages.StandardController sc = new ApexPages.StandardController(c); 
DirectMailfilter dmf = new DirectMailfilter(sc);

While I don't know which is correct, the class or the test code, you need to either adjust the test code to take a StandardSetController or adjust the class constructor to take a StandardController. Once they match, you should be all set.

  • That fixed the compiler error. It's giving another one, but I think you've solved the problem. Thanks. – Jacob Jan 7 '14 at 19:55
0

For StandardSetController you should define the test like below or you can do it in the class or trigger.

PageReference myVfPage = Page.VisualForce API Name;
Test.setCurrentPage(myVfPage);
List<You Custom Object > MyStuff = [ select id  from Your Custom Object Name];
ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(MyStuff);
CustomControllerName ext = new CustomControllerName(setcon);

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.