package com.mycompany;

import android.app.*;
import android.content.*;
import android.test.*;
import android.test.suitebuilder.annotation.*;
import android.util.*;
import android.view.*;
import android.widget.*;

import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsNull.*;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.*;
import static com.mycompany.R.id.*;

public class LoginTests extends InstrumentationTestCase {

   
@MediumTest
   
public void testAValidUserCanLogIn() {

     
Instrumentation instrumentation = getInstrumentation();

     
// Register we are interested in the authentication activiry...
     
Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(AuthenticateActivity.class.getName(), null, false);

     
// Start the authentication activity as the first activity...
     
Intent intent = new Intent(Intent.ACTION_MAIN);
      intent
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent
.setClassName(instrumentation.getTargetContext(), AuthenticateActivity.class.getName());
      instrumentation
.startActivitySync(intent);

     
// Wait for it to start...
     
Activity currentActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 5);
      assertThat
(currentActivity, is(notNullValue()));

     
// Type into the username field...
     
View currentView = currentActivity.findViewById(username_field);
      assertThat
(currentView, is(notNullValue()));
      assertThat
(currentView, instanceOf(EditText.class));
     
TouchUtils.clickView(this, currentView);
      instrumentation
.sendStringSync("MyUsername");

     
// Type into the password field...
      currentView
= currentActivity.findViewById(password_field);
      assertThat
(currentView, is(notNullValue()));
      assertThat
(currentView, instanceOf(EditText.class));
     
TouchUtils.clickView(this, currentView);
      instrumentation
.sendStringSync("MyPassword");

     
// Register we are interested in the welcome activity...
     
// this has to be done before we do something that will send us to that
     
// activity...
      instrumentation
.removeMonitor(monitor);
      monitor
= instrumentation.addMonitor(WelcomeActivity.class.getName(), null, false);

     
// Click the login button...
      currentView
= currentActivity.findViewById(login_button;
      assertThat
(currentView, is(notNullValue()));
      assertThat
(currentView, instanceOf(Button.class));
     
TouchUtils.clickView(this, currentView);

     
// Wait for the welcome page to start...
      currentActivity
= getInstrumentation().waitForMonitorWithTimeout(monitor, 5);
      assertThat
(currentActivity, is(notNullValue()));

     
// Make sure we are logged in...
      currentView
= currentActivity.findViewById(welcome_message);
      assertThat
(currentView, is(notNullValue()));
      assertThat
(currentView, instanceOf(TextView.class));
      assertThat
(((TextView)currentView).getText().toString(), is("Welcome, MyUsername!"));
   
}
}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 用VS2010开发Android应用的配置方法
  2. Android Touch事件传递机制引发的血案
  3. Android(安卓)中的 requestWindowFeature
  4. Android Studio打不开的问题
  5. android 文字图片合成
  6. Android SQLite使用方法
  7. Android RakNet 系列之三 移植Portaudio
  8. Android中的prelink技术
  9. android多国语言文件夹汇总
  10. android ui界面设计开发demo-智慧社区ui