|
TestingTutorial
#Tutorial on writing a simple TestCase IntroductionThis is a quick tutorial on writing TestCases using REST Client 2.3. DetailsREST Client has Groovy embedded. Groovy supports JUnit 3.x type test cases (if you don't know what it means, just chill, because I will be explaining this shortly). Writing Test Classpublic class MyTest extends org.wiztools.restclient.RESTTestCase{
/* TEST METHODS */
}A Sample Test MethodAll test methods should be named with prefix test. A sample test method which tests if the response body contains the text WizTools.org: public void testRequestContainsWizTools(){
if(response.getResponseBody() != null
&& (response.getResponseBody().indexOf("WizTools.org") > -1)){
// do nothing!
}
else{
fail("Response body does not have `WizTools.org' text.");
}
}Two instance variables request and response with prepopulated data is available for the test script. The methods that can be invoked on these objects are detailed here: http://code.google.com/p/rest-client/wiki/TestClass. After making the request, the Response Test Result tab will show the result of executing the Test Script. Change the text WizTools.org to ABC2XYZ. Now place the request again, this would fail the test, and be reported in the Response Test Result tab. The sample request is available here: http://rest-client.googlecode.com/files/sample-test-request-23.rcq. Download this and save to your local drive. Then open this file using File>Open Request in RESTClient interface. |
Sign in to add a comment
Nice and simple and to the point!
I'm not a Java dude, but even I got the hang of this! Just to help those having a bit of trouble, download the sample-test-request-20.xml file at the bottom of the tutorial, and you can see that the test class is embeded in the XML file itself. Very handy! So you can tie your test classes to your test requests. Neat!
Thanks subwiz!
Thanks for elucidating the point I touched in brief @omarshariffdontlikeit!
thanks for all the useful information. the sample test helped a bunch
Thanks for the tool. Has been remarkable useful combined with apache TCPmon. However, I'm looking for a way to create more elaborate tests. Can I create a script that does a POST and next a GET to verify the creation of the object on the REST server?
@marvin.brunner So far we have not managed to create Test Suites. But we have plans.