zoukankan      html  css  js  c++  java
  • Helloworld

    界面
    <?xml version="1.0" encoding="utf-8"?>
    <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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.jiangtinghui.helloworld.MainActivity"
    android:orientation="vertical">

    <TextView
    android:id="@+id/textview"
    android:text="Hello World!"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
    <EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
    <Button
    android:id="@+id/btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="SAY HELLO"/>
    </LinearLayout>

    JAVA代码

    package com.example.jiangtinghui.helloworld;

    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.TextView;

    public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    }
    public void sayHello(View view){
    TextView textView=(TextView) findViewById(R.id.textview);
    EditText editText=(EditText)findViewById(R.id.editText);
    textView.setText("Hello,"+editText.getText().toString()+"!");
    }
    }

    app代码
    apply plugin: 'com.android.application'

    android {
    compileSdkVersion 23
    buildToolsVersion "24.0.2"

    defaultConfig {
    applicationId "com.example.jiangtinghui.helloworld"
    minSdkVersion 21
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    //add for test
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
    release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    }
    }

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    //add for test
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    }

    androidTestCompile 'org.testng:testng:6.9.6'
    androidTestCompile 'org.testng:testng:6.9.6'
    }

    MainActivityInstrumentation代码

    package com.example.jiangtinghui.helloworld;

    /**
    * Created by jiangtinghui on 2017/3/16.
    */
    public class MainActivityInstrumentation {
    private static final String STRING_TO_BE_TYPED="Peter";
    @Rule
    public ActivityTestRule<MainActivity>mActivityRule=new ActivityTestRule<>(MainActivity.class);
    @Test
    public void sayHello(){
    onView(withId(R.id.editText)).perform(typeText(STRING_TO_BE_TYPED).closeSoftKeyboard());

    onView(withId(R.id.btn)).perform(click());
    String expectedText="Hello,"+STRING_TO_BE_TYPED+"!";
    onView(withId(R.id.textview)).check(matches(withText(expectedText)));
    }
    }
     
    
    
  • 相关阅读:
    C++类内存分布
    职场人理财之指数基金篇
    职场之殇---有些事情千万不能做
    职场人为什么需要理财
    职场发展之跟对老板有多重要
    职场中怎么做好一个演讲
    多线程如何按指定顺序同步执行
    多线程抢票系统浅析
    Spring Boot进阶系列三
    Spring Boot进阶系列二
  • 原文地址:https://www.cnblogs.com/42-jth/p/6559546.html
Copyright © 2011-2022 走看看