how to test queryRowToStruct ?

30 views
Skip to first unread message

Mohammed Suleman khan

unread,
Jan 30, 2014, 4:52:41 PM1/30/14
to mxu...@googlegroups.com
hi,
I have very simple query but in there I am returning it as an queryRowToStruct I have tried with some of the asserts it doesn't successfully tested.

here is my query which I am wondering to test with.

<cfquery name="q" >
       SELECT *
       FROM users AS u
       WHERE u.email = <cfqueryparam value="#arguments.email#" maxlength="60" cfsqltype="cf_sql_varchar" />
      AND u.password = <cfqueryparam value="#arguments.password#" maxlength="8" cfsqltype="cf_sql_varchar" />
  </cfquery>
  <cfif q.RecordCount EQ 1>
          <cfreturn queryRowToStruct(q) />
  </cfif>

here what checking is in case the email and password are matched the query will return a record if not it will be zero. when i have tried the below testing i got error recordCount not found though the record exists in db table. can any help me what i have to do to make this testing working ?

<cffunction name="testLogin">
        <cfargument name="email" required="false" default="ad...@yahoo.com" />
        <cfargument name="password" required="false" default="admin" />
        <cfset var x = login.login(ArgumentCollection=arguments) />
        <cfset var result = x.RecordCount />
        <!--- <cfset assertIsStruct(x) /> --->
        <cfset assertEquals(2,result) />
  </cffunction>

Thanks.

Marc Esher

unread,
Feb 3, 2014, 8:41:54 AM2/3/14
to mxu...@googlegroups.com
Is your "testLogin" function inside of a unit test? Your test function takes arguments, which is strange b/c unit tests generally do not have arguments.

try doing this:
 <cfset var x = login.login("ad...@yahoo.com", "admin") />
<cfset debug(x)> 

And then inspect the debug() output (which is a CFDump)... see here: http://wiki.mxunit.org/display/default/View+Debug+Output

The code you show indicates that if no record is found, nothing at all is returned. Consequently, X would indeed not have any data. 



--
You received this message because you are subscribed to the Google Groups "mxunit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mxunit+un...@googlegroups.com.
To post to this group, send email to mxu...@googlegroups.com.
Visit this group at http://groups.google.com/group/mxunit.
For more options, visit https://groups.google.com/groups/opt_out.

waseem khan

unread,
Feb 6, 2014, 6:02:34 AM2/6/14
to mxu...@googlegroups.com
I am using arguments just to have summary for my code so that i could know what's being passed in.  actually in the above query its get matches the email and password i will get one record if it is do not matches it won't return any record that's what I am doing that...... but the problem is it is returning a struct. anyways thanks for your reply that's too helpful.
Reply all
Reply to author
Forward
0 new messages