Robotium dual-client testing framework and robotium framework

Source: Internet
Author: User

Robotium dual-client testing framework and robotium framework

The essence of the Internet is information exchange, especially for mobile Internet. Therefore, many mobile Internet service applications have two different identities (for example, buyers and sellers in transactions, teachers and students in teaching, car owners and passengers in taxi hailing ). The most recent work is to establish an android client testing framework for a company's product. The automated testing technology used is robotium. Because the product users have two identities (clientA and clientB), we need to establish a test framework that can synchronize two different users. This is the title of"Robotium dual-client testing framework.

 

1. Detailed requirement analysis

For your convenience, I drew a picture without talking nonsense.


As described in, customer identities A and B each have some test cases to be executed (in the circular queue shown in the figure). When executing the purple test case, two clients must be synchronized, in this case, the customer identity that is executed in the use case method must communicate with the synchronization server to obtain the synchronization information of another customer identity. If the other party is ready, the use case method starts to be synchronized. If the other party is not ready, tell the server that you are ready and start waiting.

 

2. Core server code

Let's start with the code and explain it later.

Protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String methodName = request. getParameter ("testMethodName"); // more development for methods syncString clientAReady = request. getParameter ("clientAReady"); String clientBReady = request. getParameter ("clientBReady"); // debuglog ("methodName:" + methodName);/* sync code */if (clientAReady = null | clientBReady = null) {return;} if (clientAReady. equals ("unknown") {// clientB requestGlobalResource. clientBMark = "ready"; clientAReady = GlobalResource. clientAMark;} else if (clientBReady. equals ("unknown") {// clientA requestGlobalResource. clientAMark = "ready"; clientBReady = GlobalResource. clientBMark;} // write back json data}


The important thing is the intermediate if-else loop. The main function is to identify different customer identities, read the status information of another identity according to the identity, and write your status to the server.

3. Core client code

The client code can be divided into three parts: the first is the establishment of the robotium testing framework, the second is the polling of the server peer data, and the last is the need to receive data and wait for the status bit.

The establishment of the robotium testing framework is not the focus of this article, and I do not intend to explain it. Please attach the relevant information: http://www.robotium.cn/archives/210. if you have already done androiddevelopment, you should not be easy.

For server communication, I use the HttpClient framework. The method is to create an HttpClient object, send data requests to the service, and use the handler subclass provided in the Framework to asynchronously receive and process data. The code is still very simple.

 

Round-Robin data

public void testSync () throws Exception{while(ClientBReady.equals("notReady")){NetManager.TestSyncServlet("testSync", "unknown", "ready", syncHandler);Thread.sleep(5000);}//robotium control code}

Send request

package com.network.httpconnect;import com.network.httpconnect.AsyncHttpClient;import com.network.httpconnect.AsyncHttpResponseHandler;import com.network.httpconnect.RequestParams;public class NetManager {public static String getServiceBaseUrl() { return "http://localhost:8080/appTestServer/"; }public static int getTimeOut() { return 5 * 1000; }public static void TestSyncServlet(String testMethodName, String clientAReady, String clientBReady, AsyncHttpResponseHandler handler){String url = getServiceBaseUrl() + "TestSyncServlet";try{RequestParams params = new RequestParams();params.put("testMethodName", testMethodName);params.put("clientAReady", clientAReady);params.put("clientBReady", clientBReady);AsyncHttpClient client = new AsyncHttpClient();client.setTimeout(getTimeOut());client.post(url, params, handler);}catch (Exception ex){ex.printStackTrace();if (handler != null)handler.onFailure(null, ex.getMessage());}}}


Receive data


private AsyncHttpResponseHandler syncHandler = new AsyncHttpResponseHandler(){@Overridepublic void onSuccess(String content) {super.onSuccess(content);debuglog("content:"+ content);try {JSONObject receiveData = new JSONObject(content);ClientBReady = receiveData.getString("ClientBReady");} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}}@Overridepublic void onFailure(Throwable error, String content) {super.onFailure(error, content);}};

 

Due to the limited level of the author, the implementation of this article may not be very perfect. I have uploaded the code to github. If you are not clear about it, please refer to the source code.

Github address: https://github.com/cibon/robotium_two_clients_framework.





Do you have any suggestions for testing platforms based on the Robotium framework?

For APP testing, we recommend a cloud testing platform called cloud testing.

The Android Robotium Framework's self-written Automatic Test Program has no results

No specific error is reported and you cannot answer it in detail. please upload the exception details
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.