[Webtest] Re: testing JSON web services

Tokutan Tokutan <tokutan@gmail.com>
Wed, 10 Sep 2008 09:28:25 +1000


------=_Part_179635_10413394.1221002905219
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi Marc,

Thanks for replying. From what i have gathered, Web services is a rest-based
and outputting JSON as the expected output. I have played around with
webtest with invoke contentfile and Webtest does recognise the output.
However, at the moment management is more inclined to use JMETER for this
purpose as we need to connect to mysql via JDBC in order to clean up the
database prior to running the test. I find JMETER to be really basic in
terms of functional web testing as it is more towards performance testing

I need to present to the management the benefit of using Webtest for this
web services testing. I have managed to use SQLunit to connect mysql via
JDBC , however I have not figured out how to incorporate SQLUnit inside
webtest script (I have just managed to run SQL unit individually by telling
it to output webtest report by this command:ant sqlunit-nested canoo2html
-Dtestdir=testwedi -Dlog.format=canoo -Doutput.file=results.xml
-Dwebtest.style=WebTestReport

Lets say I have the following simple webtest script:

<!DOCTYPE project SYSTEM "../dtd/Project.dtd">

<project default="test">


    <target name="test">


        <dataDriven tableContainer="testsip.xls" table="testjson">


        <webtest name="check soap">
        <config haltonerror="false" haltonfailure="false"  >

         <option name="ThrowExceptionOnScriptError"
        value="false"
        />
              <option name="ThrowExceptionOnFailingStatusCode"
        value="false"
        />
        <header name="User-Agent" value="Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"/>

     </config>




   <invoke method="GET" url="${URL}"/>

     <applyFilters>

        <matchLinesFilter regex="\d"/>
        </applyFilters>


          <verifyContent referenceFile="json.html"/>


</webtest>
</dataDriven>
</target>
</project>

And I have the following simple SQLunit script:

  <test name="Checking returned value from customer"
          failure-message="Returned value check for customer failed">
    <sql>
      <stmt>SELECT category_alias_name FROM
Fads_ForQARnD.category_alias_to_c1_category_mappings where
category_alias_name ='Banking'</stmt>

    </sql>
    <result>
      <resultset id="1">
        <row id="1">
          <col id="1" name="category_alias_name"
type="VARCHAR">Banking</col>
        </row>
      </resultset>
    </result>

How can i incorporate SQLunit script inside webtest script so webtest will
run SQLunit script firstly and then running subsequent webtest script?

Thanks
  </test>

------=_Part_179635_10413394.1221002905219
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<div dir="ltr">Hi Marc,<br><br>Thanks for replying. From what i have gathered, Web services is a rest-based and outputting JSON as the expected output. I have played around with webtest with invoke contentfile and Webtest does recognise the output. However, at the moment management is more inclined to use JMETER for this purpose as we need to connect to mysql via JDBC in order to clean up the database prior to running the test. I find JMETER to be really basic in terms of functional web testing as it is more towards performance testing<br>
<br>I need to present to the management the benefit of using Webtest for this web services testing. I have managed to use SQLunit to connect mysql via JDBC , however I have not figured out how to incorporate SQLUnit inside webtest script (I have just managed to run SQL unit individually by telling it to output webtest report by this command:ant sqlunit-nested canoo2html -Dtestdir=testwedi -Dlog.format=canoo -Doutput.file=results.xml -Dwebtest.style=WebTestReport <br>
<br>Lets say I have the following simple webtest script:<br><br>&lt;!DOCTYPE project SYSTEM &quot;../dtd/Project.dtd&quot;&gt;<br><br>&lt;project default=&quot;test&quot;&gt;<br><br><br>&nbsp;&nbsp;&nbsp; &lt;target name=&quot;test&quot;&gt;<br>
&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;dataDriven tableContainer=&quot;testsip.xls&quot; table=&quot;testjson&quot;&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;webtest name=&quot;check soap&quot;&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;config haltonerror=&quot;false&quot; haltonfailure=&quot;false&quot;&nbsp; &gt;<br>
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;option name=&quot;ThrowExceptionOnScriptError&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; value=&quot;false&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &lt;option name=&quot;ThrowExceptionOnFailingStatusCode&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; value=&quot;false&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;header name=&quot;User-Agent&quot; value=&quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:<a href="http://1.8.1.14">1.8.1.14</a>) Gecko/20080404 Firefox/<a href="http://2.0.0.14">2.0.0.14</a>&quot;/&gt; <br>
<br>&nbsp;&nbsp;&nbsp; &nbsp;&lt;/config&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp; &lt;invoke method=&quot;GET&quot; url=&quot;${URL}&quot;/&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;applyFilters&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;matchLinesFilter regex=&quot;\d&quot;/&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/applyFilters&gt;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &lt;verifyContent referenceFile=&quot;json.html&quot;/&gt; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <br><br>&lt;/webtest&gt;<br>&lt;/dataDriven&gt;<br>&lt;/target&gt;<br>&lt;/project&gt;<br>
<br>And I have the following simple SQLunit script:<br><br>&nbsp; &lt;test name=&quot;Checking returned value from customer&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; failure-message=&quot;Returned value check for customer failed&quot;&gt;<br>&nbsp;&nbsp;&nbsp; &lt;sql&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;stmt&gt;SELECT category_alias_name FROM Fads_ForQARnD.category_alias_to_c1_category_mappings where category_alias_name =&#39;Banking&#39;&lt;/stmt&gt;<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;/sql&gt;<br>&nbsp;&nbsp;&nbsp; &lt;result&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;resultset id=&quot;1&quot;&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;row id=&quot;1&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;col id=&quot;1&quot; name=&quot;category_alias_name&quot; type=&quot;VARCHAR&quot;&gt;Banking&lt;/col&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/row&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/resultset&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/result&gt;<br>
<br>How can i incorporate SQLunit script inside webtest script so webtest will run SQLunit script firstly and then running subsequent webtest script?<br><br>Thanks<br>&nbsp; &lt;/test&gt;<br></div>

------=_Part_179635_10413394.1221002905219--