+ Start a Discussion
1111_forcecom1111_forcecom 

Error test class apex

Hi everybody,

 

Can you help me please, i have this error in my apex class test, and I don't know for why

 

ERROR: Error de compilación: Invalid constructor name: contactExtension en la línea 3 columna 16

 

@isTest 

public class ContactTest {
public contactExtension(ApexPages.StandardController contactController) {
this.contact = (Contact)contactController.getRecord();
String idContact = contact.id;
}

static testmethod void myTestMethod1() {
Moneda__c monedabob = [select Name from Moneda__c where Moneda__c.name = 'Bolivianos'];
System.assert(monedabob != null);
String idMonedabob = monedabob.id;
Double x = 0;
for (Beneficio__c ben : [select monto_estimado__c from Beneficio__c where Contacto__c = :idContact and Moneda__c = :idMonedabob]){
x = ben.monto_estimado__c + x;
}

}
}

 

Regard,

 

Ale

Best Answer chosen by 1111_forcecom
bob_buzzardbob_buzzard

This code:

 

public contactExtension(ApexPages.StandardController contactController) {
  this.contact = (Contact)contactController.getRecord();
  String idContact = contact.id;
}

 

is defining a constructor for the contactExtension class, but you are in a test class so that is illegal.  This should be in a class named contactExtension and your test code should probably execute it.

 

All Answers

bob_buzzardbob_buzzard

This code:

 

public contactExtension(ApexPages.StandardController contactController) {
  this.contact = (Contact)contactController.getRecord();
  String idContact = contact.id;
}

 

is defining a constructor for the contactExtension class, but you are in a test class so that is illegal.  This should be in a class named contactExtension and your test code should probably execute it.

 

This was selected as the best answer
1111_forcecom1111_forcecom
Thank you so much for your answer, the class contactExtension be here, for the test apex class, I should be take one unique contact? or set the id contact? is this valid?

Please help me, this is new.

Regards,
bob_buzzardbob_buzzard

The issue is you can't have a constructor in the test class - if you are testing a controller, you need to create an instance of the controller in the test class, not replicate the constructor.

1111_forcecom1111_forcecom
Thank you for your answer, can you explain me with an example please?

Regards,