+ Start a Discussion
Matthew RogersMatthew Rogers 

Invalid type: OpportunitiesController test class error?

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() {
    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();

Meghna Vijay 7Meghna Vijay 7
Hi Matthew.

Your class name is OpportunityController and you are writing "OpportunitiesController" . Change it to "OpportunityController".

Hope it helps, if it does, mark it as solved.

Matthew RogersMatthew Rogers
Hi Meghna,

Haa - very silly of me. 

I am now receiving 2 more errors, would you happen to know what these are about?

Method does not exist or incorrect signature: void save() from the type OpportunityController
Method does not exist or incorrect signature: void getOpportunity() from the type OpportunityController

Thank you! 
Meghna Vijay 7Meghna Vijay 7

These two methods does not exist in OpportunityController and you are doing the query in constructor.

Deepali KulshresthaDeepali Kulshrestha
Hi Matthew,
Greetings to you!

- I read your problem and implemented in my Org.
- Please use the below test class [Solved] : -
public class opportunityControllerTest {
     public static testMethod void opportunityControllerMethod() {    
     OpportunityController OpportunitiesControllerObj = new OpportunityController();

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
Tad Aalgaard 3Tad Aalgaard 3
References to class names should be uppercase.
Instance variable names should be lower case.
Asserts should be added.  It is not really a test class unless it is testing something.
testMethod it deprecated.
Unless you plan on calling the test class or test methods of this class from another test class then the test class should be made to be private.

private class OpportunityControllerTest {
    static void opportunityControllerMethod() {
        OpportunityController opportunitiesControllerObj = new OpportunityController();
        System.assert (opportunitiesControllerObj != null);