METHOD DOES NOT EXIST during unittest attempts
Hello,
as i'm trying to develop a operation and its methods (SQL adapter), I'm running into issues when i run my test class.
I have the class i want to test in the very same folder as my test class.
I followed the tutorial in the documentation.
When i run the test class, i get the following message error :
LogStateStatus:0::ERREUR #5002: Erreur Cache: <METHOD DOES NOT EXIST>zTestAdd+1^unitTests.testMyClass.1 *myMethod,Package.BO.MyClass
Here is my test class (heavily inspired bythe documentation :-) :
Class unitTests.testSqlInscription Extends %UnitTest.TestCase
{
Method TestMyMethod()
{
do $$$AssertEquals(##class(unitTests.sqlInscription).getIdByEmail(2013569),1953642, "Test MyMethod()=1953642")
}
}
Here is a overview of the class and the method i'm testing (modified for confidentiality reasons) :
Include EnsSQLTypes
Class unitTests.sqlInscription Extends Ens.BusinessOperation
{
Parameter ADAPTER = "Custom.SQL.OutboundAdapter";
Property Adapter As Custom.SQL.OutboundAdapter;
Parameter INVOCATION = "Queue";
Method getIdByEmail(pRequest As Package.Msg.myMethodRequest, Output pResponse As Package.Msg.myMethodResponse) As %Status
{
set tStatus = $$$OK
try{
s pResponse = ##class(Package.Msg.myMethodResponse).%New()
s sqlGetid = " SELECT TOP 1 id FROM [database].Table WHERE email = ? "
$$$ThrowOnError(..Adapter.ExecuteQuery(.tResult, sqlGetid , pRequest.someProperty))
set id = ""
if (tResult.Next())
{
set id = tResult.Get("column_id") // id being the column in the database
}
s pResponse.myOutput = idTiers
}
catch exp{
Set tStatus = exp.AsStatus()
}
Quit tStatus
}
The execution of teh test is done properly (UnitTestRoot is configured correctly, the test class seemed to be found and executed, but the method i'm rtying to test cannot be located for some reason)
I can't make sense of it at all, any help is much appreciated.
Thank you
Your method is declared with "Method getIdByEmail(...". The "Method" keyword marks it as an instance method, which would need a class instance to access. Your unit test calls "##class(unitTests.sqlInscription).getIdByEmail(...", which is the syntax for calling a class method. You can declare your method with the "ClassMethod" keyword: "ClassMethod getIdByEmail(..." or you can instantiate your unitTests.sqlInscription class.
Ok i'll get going on instanciating the class first and see what it does.
The classMethod present a problem with the adapter method that i call.
Thanks for your input.
So I instantiated the class but it didn't work either
terminal :
unitTests.testSqlAgateInscription begins ...
TestMyMethod() begins ...
LogStateStatus:0:TestMyMethod:ERREUR #5002: Erreur Cache: <INVALID OREF>zTestMyMethod+4^unitTests.testSqlInscription.1 <<==== **FAILED**
unitTests:unitTests.testSqlInscription:TestMyMethod:
TestMyMethod failed
unitTests.testSqlInscription failed
unitTests failed
The code looks like that :
Class unitTests.testSqlInscription Extends %UnitTest.TestCase
{
Method TestMyMethod()
{
set myObject = ##class(Package.BO.sqlInscription).%New()
set myRequest = ##class(Package.Msg.getSomeDataFromDataBaseRequest).%New()
set myRequest.somePropertyaboutEmail = "test@mail.com"
do $$$AssertEquals(myObject.getSomeDataFromDataBase(myRequest),1953642, "Test MyMethod()=1953642")
}
}
I'm really out of ideas here to set up a basic unit test. Any hint is much welcome.
Please and thank you.