App vs. background interaction and Web vs. background interaction (App simple test environment) __web

Source: Internet
Author: User
Tags gettext test web server

Foreword:
Previous work has been done on the web side of the test, and performance testing is mainly to simulate the web side to send HTTP requests to the server. There is less understanding of the system and framework of app. Because the next job is primarily to test the performance of the app server. On the Internet to find some information, simple to build an app test environment. Also want to be able to use JMeter simulate app to send request to the server. So only for beginners and I learn to see, the great God not to spray
before I have built a very simple javaweb application, to achieve the use of Javaservlet landing process. Referring to the previous blog post,
now uses ADT to create an Android project based on the Loginservlet development app-side program 1. Layout my understanding is to interact with the user interface, which belongs to the front-end of the app
Configure some code in Layout activity_main.xml

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"
  xmlns:tools= "http:// Schemas.android.com/tools "
  android:layout_width=" match_parent "
  android:layout_height=" Match_parent "
  android:orientation= "vertical"
  tools:context= ". Mainactivity ">

  <edittext 
    android:id=" @+id/nametext "
    android:layout_width=" Match_parent " android:layout_height= "Wrap_content"
    android:hint= "username"/> <edittext android:id= 
    "@+id/" Pwdtext "
    android:layout_width=" match_parent "
    android:layout_height=" wrap_content "
    android:hint=" "Password"/>

  <button
    android:id= "
    @+id/button1" android:layout_width= "Match_parent" android:layout_height= "Wrap_content"
    android:text= "submit"/>

</LinearLayout>
2 Enter the following code in the Mainactivity.java, beginners understand: This Java is equivalent to processing layout sent over the data. Some of the front-end calibration work can be done here, and the specific processing work can also be done here. This is the user input to receive layout, and then click Login to send HTTP requests to the server using the Get method
Package com.example.test;
Import Java.io.BufferedReader;
Import Java.io.InputStreamReader;
Import java.util.ArrayList;
Import org.apache.http.HttpEntity;
Import Org.apache.http.HttpResponse;
Import Org.apache.http.NameValuePair;
Import org.apache.http.client.HttpClient;
Import org.apache.http.client.entity.UrlEncodedFormEntity;
 Import Org.apache.http.client.methods.HttpGet;
 Import Org.apache.http.client.methods.HttpPost;
Import org.apache.http.impl.client.DefaultHttpClient;

Import Org.apache.http.message.BasicNameValuePair;
 Import android.app.Activity;
 Import Android.os.Bundle;
Import Android.util.Log;
 Import Android.view.View;
Import Android.view.View.OnClickListener;
 Import Android.widget.Button;

Import Android.widget.EditText;
    public class Mainactivity extends activity {private EditText nametext;
    Private EditText Pwdtext;

   Private button button;
 @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);      Setcontentview (R.layout.activity_main);
      Nametext = (edittext) Findviewbyid (R.id.nametext);
        Pwdtext = (edittext) Findviewbyid (R.id.pwdtext);

       Button = (button) Findviewbyid (R.id.button1);
                 Button.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) { TODO auto-generated Method Stub//user enter username password and send to local server String name = Name
               Text.gettext (). toString ();

            String pwd = Pwdtext.gettext (). toString ();
                Runs the thread, using the Get method to send data to the local server getthread getthread = new GetThread (name, PWD);
          Getthread.start ();
    }
        });
       }//Child thread: Send user name, password information to server via Get method class GetThread extends thread {String name;

       String pwd;
            Public GetThread (string name, string pwd) {this.name = name;
       This.pwd = pwd;
       @Override public void Run () {   Send a request with httpclient, divided into five steps//First step: Create HttpClient object HttpClient httpclient = new Defaulthttpclient (); Note that in the following line, I wrote the link "test" mistakenly written "text", causing the bug tuned for half a day did not come out, it is a waste of time ah String url = "Http://localhost:8080/LoginSer
           Vlet/loginservlet?name= "+ name+" &password= "+ pwd;
       Step Two: Create the object that represents the request, and the parameter is the server address httpget HttpGet = new HttpGet (URL) that is accessed;
               try {//Step three: Execute the request, get the corresponding object of the server reimbursement HttpResponse response = Httpclient.execute (HttpGet);
                   Step Fourth: Check that the appropriate state is normal: Check the status code value is 200 to indicate normal if (Response.getstatusline (). Getstatuscode () = = 200) {
                Fifth step: From the corresponding object to take out the data, put into the entity httpentity entity = response.getentity ();
                   BufferedReader reader = new BufferedReader (New InputStreamReader (Entity.getcontent ()));
                    String result = Reader.readline ();
              LOG.D ("HTTP", "Get:" + result); }} CATCH (Exception e) {e.printstacktrace ();  }

        }
    }
}

I added the print code to the front Loginservlet.java. If you have a request, print the information. Used to verify that the request was sent successfully.

So far: The interactive simulation process between app end and server side has been completed analysis
As can be seen from the business logic, the app side interacts with the server almost as much as the web side and the server, and can be considered a set of servers, two different clients. The background described above uses the same javaservlet, one is accessed through the static Web page of HTML, the other is accessed through the app side, and the effect is the same for the server side.

So there are testers who test Web server performance without having to worry about not testing the server performance of the app. They are the same set of background, test server performance directly simulate the web side is OK. If there is no web side, only the app side, test performance, you can find the corresponding developers to provide HTTP request messages. and put it in the jmeter for testing.
Of course, there is also a way to use Javasampler directly invoke the background interface for testing. This should be done in the light of the front javasampler.

Source of code:
Http://www.cnblogs.com/smyhvae/p/4006009.html

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.