• Matthew Rogers
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I am trying to write a test class for a simple Controller.. I think I am along the right lines but have an error: Invalid type: OpportunitiesController.. please help!

Custom Controller
public class OpportunityController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityController() {
        opp = [SELECT Id, Name, CreatedDate, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, Key_Responsibilities__c, Skills_Required__c, Account.Name, Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity WHERE (StageName = '1 - Qualifying' or StageName = '2 - Booked for CK' or StageName = '3 - Live' or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice')];
        	}
}

Test Class method 
 
static testMethod void myUnitTest2() {
    test.startTest();
			        
    Opportunity opp = new Opportunity();
    opp.Name = ' test 001';
			  
    insert opp;
			  		
    PageReference testPage = new pagereference('/apex/Opportunities');
    ApexPages.currentPage().getParameters().put( 'id', opp.id );

    OpportunitiesController OpportunitiesControllerObj = new OpportunitiesController();
	PageReference pageref = OpportunitiesControllerObj.save();
	OpportunitiesControllerObj.getOpportunity();
     test.stopTest();
}

 
public class OpportunityController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityController() {
        opp = [SELECT Id, Name, CreatedDate, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, 
				NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, Key_Responsibilities__c, 
				Skills_Required__c, Account.Name, Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity 
				WHERE (StageName = '1 - Qualifying' or StageName = '2 - Booked for CK' or StageName = '3 - Live'
               or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice')];
        	}
}

I can't figure out how to approach it for a custom and not standard controller

Thank you

I am trying to write a test class for a simple Controller.. I think I am along the right lines but have an error: Invalid type: OpportunitiesController.. please help!

Custom Controller
public class OpportunityController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityController() {
        opp = [SELECT Id, Name, CreatedDate, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, Key_Responsibilities__c, Skills_Required__c, Account.Name, Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity WHERE (StageName = '1 - Qualifying' or StageName = '2 - Booked for CK' or StageName = '3 - Live' or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice')];
        	}
}

Test Class method 
 
static testMethod void myUnitTest2() {
    test.startTest();
			        
    Opportunity opp = new Opportunity();
    opp.Name = ' test 001';
			  
    insert opp;
			  		
    PageReference testPage = new pagereference('/apex/Opportunities');
    ApexPages.currentPage().getParameters().put( 'id', opp.id );

    OpportunitiesController OpportunitiesControllerObj = new OpportunitiesController();
	PageReference pageref = OpportunitiesControllerObj.save();
	OpportunitiesControllerObj.getOpportunity();
     test.stopTest();
}

 
public class OpportunityController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityController() {
        opp = [SELECT Id, Name, CreatedDate, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, 
				NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, Key_Responsibilities__c, 
				Skills_Required__c, Account.Name, Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity 
				WHERE (StageName = '1 - Qualifying' or StageName = '2 - Booked for CK' or StageName = '3 - Live'
               or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice')];
        	}
}

I can't figure out how to approach it for a custom and not standard controller

Thank you