i'm trying improve writing functional automated tests rest api's
here sample:
q1 can critic tests or see if there room improvements?
q2 i'm planning write series of api tests in apptest class...is there way or function or utility can store responses in file or execute series of api tests ?
package com.jaway.restassured.rest_assured; import static com.jayway.restassured.restassured.get; import java.util.list; import org.json.jsonexception; import org.json.jsonarray; import org.testng.assert; import org.testng.*; import org.testng.annotations.test; import org.testng.annotations.*; import org.testng.annotations.dataprovider; import org.testng.asserts.softassert; import com.jayway.restassured.response.*; public class apptest { string url = "http://restcountries.eu/rest/v1/name/"; @test(dataprovider = "getdata") public void getrequestfindcapital(string country, string expected_capital, string expected_region, string expected_trans_it ) throws jsonexception{ softassert softassert = new softassert(); //make request fetch capital of norway response resp = get(url + country); system.out.println(url + country); jsonarray jsonresponse =new jsonarray(resp.asstring()); system.out.println(resp.asstring()); //declare variables string actual_capital = jsonresponse.getjsonobject(0).getstring("capital"); string actual_region = jsonresponse.getjsonobject(0).getstring("region"); list<object> actual_translations = resp.jsonpath().getlist("translations.it"); string actual_translations_string = actual_translations.tostring().replaceall("[\\[\\]]", ""); system.out.println(actual_translations); system.out.println(actual_translations_string); softassert.assertequals(actual_capital, expected_capital); softassert.assertequals(actual_region, expected_region); softassert.assertequals(actual_translations_string, expected_trans_it); softassert.assertall(); } @dataprovider public object[][] getdata() { return new object[][]{ {"norway", "oslo","europe", "norvegia"}, {"britain", "london","europe","regno unito"}, {"bangladesh","dhaka","asia","bangladesh"}}; } }
i write itests in openejb or arquillian. openejb test class can start embedded container before launch tests. can view examples here: http://openejb.apache.org/examples-trunk/index.html. jee6 compliant, jee7 not released yet...
Comments
Post a Comment