????Instrumentation??android??????????
???????????? ???????[ 2015/9/10 16:02:53 ] ??????????????? ???????
??????????????ο???
MainActivity????
package com.example.jc.instrumentsample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity implements View.OnClickListener {
private Button btn;
private TextView tv;
private EditText num1;
private EditText num2;
private EditText rs;
private Button mult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button_change);
btn.setOnClickListener(this);
tv = (TextView) findViewById(R.id.textView_hello);
num1 =(EditText)findViewById(R.id.editText_num1);
num2 =(EditText)findViewById(R.id.editText_num2);
rs = (EditText)findViewById(R.id.editText_rs);
mult = (Button)findViewById(R.id.button_multip);
mult.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button_change:
changeTextView();
break;
case R.id.button_multip:
computeMultip();
default:
break;
}
}
//???
private void computeMultip() {
double n1 = Double.parseDouble(num1.getText().toString());
double n2 = Double.parseDouble(num2.getText().toString());
double res = n1*n2;
rs.setText(String.valueOf(res));
}
// textView?任
private void changeTextView() {tv.setText("this is my first android");}
// ???
public int add(int a?? int b) {return a + b;}
//????
public int sub(int a?? int b) {return b - a;}
}
sampleTest
package com.example.jc.instrumentsample;
import android.content.Intent;
import android.os.SystemClock;
import android.test.InstrumentationTestCase;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**
* Created by jc on 15/9/1.
*/
public class sampleTest extends InstrumentationTestCase {
private MainActivity sample = null;
private Button btn = null;
private TextView textView = null;
private EditText num1 = null;
private EditText num2 = null;
private EditText rs = null;
private Button mult = null;
@Override
protected void setUp() throws Exception {
try {
Log.d("1111"??"111");
super.setUp();
}catch (Exception e){
e.printStackTrace();
}
Intent intent = new Intent();
intent.setClassName("com.example.jc.instrumentsample"?? MainActivity.class.getName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sample = (MainActivity)getInstrumentation().startActivitySync(intent);
btn = (Button)sample.findViewById(R.id.button_change);
textView = (TextView)sample.findViewById(R.id.textView_hello);
num1 = (EditText)sample.findViewById(R.id.editText_num1);
num2 = (EditText)sample.findViewById(R.id.editText_num2);
rs = (EditText)sample.findViewById(R.id.editText_rs);
mult = (Button)sample.findViewById(R.id.button_multip);
}
@Override
protected void tearDown() throws Exception {
sample.finish();
try {
super.tearDown();
}catch (Exception e){
e.printStackTrace();
}
}
public void testMultip(){
SystemClock.sleep(1000);
getInstrumentation().runOnMainSync(new PerFromClickMultip(mult));
SystemClock.sleep(1000);
assertEquals("210.0"?? rs.getText().toString());
}
private class PerFromClickMultip implements Runnable {
private Button m = null;
public PerFromClickMultip(Button mult) {
m = mult;
}
@Override
public void run() {
num1.setText(String.valueOf(21));
num2.setText(String.valueOf(10));
double n1 = Double.parseDouble(num1.getText().toString());
double n2 = Double.parseDouble(num2.getText().toString());
double n3 = n1* n2;
rs.setText(String.valueOf(n3));
}
}
public void testActivity(){
Log.d("testActivity"??"testActivity");
SystemClock.sleep(1500);
getInstrumentation().runOnMainSync(new PerFromClick(btn));
SystemClock.sleep(1500);
assertEquals("hello andriod"??textView.getText().toString());
}
private class PerFromClick implements Runnable {
Button btn2;
public PerFromClick(Button button){
btn2 = button;
}
@Override
public void run() {
btn2.performClick();
}
}
public void testAdd(){
String tag = "testAdd";
Log.d("testActivity"??"testAdd");
int test = sample.add(1??1);
assertEquals(3??test);
}
public void testSub(){
String tag = "testSub";
Log.d("testActivity"??"testAdd");
int test = sample.sub(2??1);
assertEquals(1??test);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jc.instrumentsample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<uses-library android:name="android.test.runner" />
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.jc.instrumentsample" />
</manifest>
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Android???????????????Щ???????????Android????????????????????????Щ??Android ??????????????????????????APP?????android???????????????Android App ?????????Android Unit Test ?????Android?????????Robolectric3.0????(?)Android??????????????Android Studio???????????Android????MySQL????????????????Android MVP???????Android ?????????ActiveAndroid??дAndroid??????????????????????Android????????Java??????????Android????????Java8Java / Android ????????????????Щ??
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????