package com.example.kevin.helloword;import android.support.v7.app.ActionBarActivity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.widget.Toast;publicclassMainActivityextends ActionBarActivity {
@Override
protectedvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button =(Button) findViewById(R.id.button);final TextView tx =(TextView)findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener(){
@Override
publicvoidonClick(View v){
Toast.makeText(MainActivity.this,"helloWorld",Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this,"杨彦星",Toast.LENGTH_LONG).show();
tx.setText("hello yyx");}});}
@Override
publicbooleanonCreateOptionsMenu(Menu menu){// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);returntrue;}
@Override
publicbooleanonOptionsItemSelected(MenuItem item){// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();//noinspection SimplifiableIfStatement
if(id == R.id.action_settings){returntrue;}returnsuper.onOptionsItemSelected(item);}}
package com.example.kevin.helloword;import android.test.ActivityInstrumentationTestCase2;import com.robotium.solo.Solo;publicclasshelloTestextends ActivityInstrumentationTestCase2<MainActivity>{private Solo solo;publichelloTest(){super(MainActivity.class);}
@Override
publicvoidsetUp()throws Exception {//setUp() is run before a test case is started.
//This is where the solo object is created.
solo =new Solo(getInstrumentation(), getActivity());}
@Override
publicvoidtearDown()throws Exception {//tearDown() is run after a test case has finished.
//finishOpenedActivities() will finish all the activities that have been opened during the test execution.
solo.finishOpenedActivities();}publicvoidtestclickMe()throws Exception{
solo.unlockScreen();
solo.clickOnButton("click me");boolean expected =true;boolean actual = solo.searchText("hello yyx");
assertEquals("word not change", expected, actual);}}