You need to sign in to do that
Don't have an account?
Mats Eriksson
Testing of getter;setter
I have problems testing my getter/setter. I'm rather new to it and am missing the nuances.
I have a class that looks like this:
public with sharing class clsCheckDuplicateSerials { public string CheckDuplicateSerials{get; set;} String srchText; public String getSearchText() { return srchText; } public void setSearchText(String s) { srchText = s; } }
The test method looks like this:
@isTest private class TestDuplicateISerials { static testMethod void myUnitTest() { String sText ='ABX9043092058'; CheckDuplicateSerials mm= new CheckDuplicateSerials(); mm.getSearchText =sText; String s = mm.getSearchText ; systemAssert(sText,s) } }
This doesn't work, I get "Variable does not exist: getSearchText". I have tried different methods of assignment but only the error messages change.
It's the test class that fails, the first one doesn't throw any errors.
I'm aware of the issue with execution order of the getter and setter but ignoring it for the moment, just want to be able to get the testing going.
Any advice?
/Mats
There's a couple of things that jump out at me:
(1) Your class is called clsCheckDuplicateSerials, but in the test class you instantiate CheckDuplicateSerials - is that a cust/paste error? otherwise I wouldn't expect it to save.
(2) get/setSearchText are methods, but you are trying to use them like properties. I think you want something like:
All Answers
There's a couple of things that jump out at me:
(1) Your class is called clsCheckDuplicateSerials, but in the test class you instantiate CheckDuplicateSerials - is that a cust/paste error? otherwise I wouldn't expect it to save.
(2) get/setSearchText are methods, but you are trying to use them like properties. I think you want something like:
Thanks for your answer.
Yes, the class name was a typo when composing the posting on this site.
However, I actually tried before posting with calling the methods like you describe but came across: TestDuplicateSerials: Method does not exist or incorrect signature: [CheckDuplicateSerials].GetSearchText(String)
Another typo somewhere?
/Mats
This error:
: [CheckDuplicateSerials].GetSearchText(String)
Implies you have done something like:
I.e. you have tried to call the getSearchText with a string parameter, but there is no method with that signature.
Gack!
Another typo....
Thank you Bob for your help!
@istest
private class clsCheckDuplicateSerials_test
{
static testmethod void check()
{
clsCheckDuplicateSerials nm=new clsCheckDuplicateSerials();
string sText='ABX9043092058';
nm.getSearchText();
nm.setSearchText(sText);
}
}
this should help i think:)
I am expereincing same situation but i am not able to cover the get method.
below is the snippet,
below is my test method.
I am getting error message as invalid type PhdOppDocuments. PhdOppDocuments is a class defined in the controller class.
Please help mw covering this class.
Aariff