2

I'm trying to write a unit test for my Timeline apex class but I keep getting an error: "Compilation error: Constructor not defined:[Timeline].<Constructor>".

@isTest
public class TimelineTest {
    public static testMethod void testTimeline() {      
        Test.startTest();

        Participant__c participant = new Participant__c();
        participant.First_Name__c = 'test';
        participant.Last_Name__c = 'user';
        participant.Client_Id__c = '1101';
        participant.DOB__c =  Date.newInstance(1976,1,1);
        insert participant;

        Timeline t = new Timeline();
        t.pid = participant.Id;
        t.violations;

        Test.stopTest();
    }
}

My Timeline class looks like this:

public class Timeline {
    public String pid {get;set;}
    public Timeline(ApexPages.StandardController controller) {
        pid = ApexPages.currentPage().getParameters().get('Id');
        violations = JSON.serialize( Database.query('SELECT...') );
    }
}

1 Answer 1

1

It looks like the constructor Timeline() is not defined. Therefore you can ether implement the method Timeline() in your Class Timeline or you can use the already defined constructor.

Create a standard controller / set the url parameter:

Apexpages.currentPage().getParameters().put('Id', participant.id);
ApexPages.StandardController sc = new ApexPages.standardController(participant);

//initalize timeline
Timeline t = new Timeline(sc);
3
  • I added my Timeline class to the question. Can you take a look at it again? Thanks.
    – anwarabq
    May 12, 2015 at 11:25
  • Thanks. I added your code and I got a similar error. Then I changed ApexPages.StandardController sc = new ApexPages.standardController(participant.id); to ApexPages.StandardController sc = new ApexPages.standardController(participant); I think it works now. At least no errors.
    – anwarabq
    May 12, 2015 at 11:39
  • If Christian's response answered your question, click to vote it up and accept it as the solution.
    – Rob
    May 12, 2015 at 13:58

You must log in to answer this question.

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