• 老李分享:Robotium创建Note的实例


    老李分享:Robotium创建Note的实例

     

    poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-84505200。

    <pre name="code" class="java">package com.example.android.notepad.test;

    import com.robotium.solo.Solo;

    import android.test.ActivityInstrumentationTestCase2;

    import android.app.Activity;

    @SuppressWarnings("rawtypes")

    public class TCCreateNote extends ActivityInstrumentationTestCase2{

             private static Solo solo = null;

             public Activity activity;

            

             private static final int NUMBER_TOTAL_CASES = 2;

             private static int run = 0;

            

             private static Class<?> launchActivityClass;

             //对应re-sign.jar生成出来的信息框里的两个值

             private static String mainActiviy = "com.example.android.notepad.NotesList";

             private static String packageName = "com.example.android.notepad";

             static {

                       try {

                                launchActivityClass = Class.forName(mainActiviy);

                       } catch (ClassNotFoundException e) {

                                throw new RuntimeException(e);

                       }

             }

            

            

             @SuppressWarnings("unchecked")

             public TCCreateNote() {

                       super(packageName, launchActivityClass);

             }

            

             @Override

             public void setUp() throws Exception {

                       //setUp() is run before a test case is started.

                       //This is where the solo object is created.

                       super.setUp();

                       //The variable solo has to be static, since every time after a case's finished, this class TCCreateNote would be re-instantiated

                       // which would lead to soto to re-instantiated to be null if it's not set as static

                       if(solo == null) {

                                TCCreateNote.solo = new Solo(getInstrumentation(), getActivity());

                       }

             }

            

             @Override

             public void tearDown() throws Exception {

                       //Check whether it's the last case executed.

                       run += countTestCases();

                       if(run >= NUMBER_TOTAL_CASES) {

                                solo.finishOpenedActivities();

                       }

             }

             public void testAddNoteCNTitle() throws Exception {

                      

                       solo.clickOnMenuItem("Add note");

                       solo.enterText(0, "中文标签笔记");

                       solo.clickOnMenuItem("Save");

                       solo.clickInList(0);

                       solo.clearEditText(0);

                       solo.enterText(0, "Text 1");

                       solo.clickOnMenuItem("Save");

                       solo.assertCurrentActivity("Expected NotesList Activity", "NotesList");

                      

                       solo.clickLongOnText("中文标签笔记");

                       solo.clickOnText("Delete");

             }

            

            

             public void testAddNoteEngTitle() throws Exception {

                       solo.clickOnMenuItem("Add note");

                       solo.enterText(0, "English Title Note");

                       solo.clickOnMenuItem("Save");

                       solo.clickInList(0);

                       solo.clearEditText(0);

                       solo.enterText(0, "Text 1");

                       solo.clickOnMenuItem("Save");

                       solo.assertCurrentActivity("Expected NotesList Activity", "NotesList");

                      

                       solo.clickLongOnText("English Title Note");

                       solo.clickOnText("Delete");

             }

    }

  • 相关阅读:
    Python eval 函数妙用
    502与504故障分析与解决方法
    [转]谈谈select, iocp, epoll,kqueue及各种网络I/O复用机制
    计算阶乘n!末尾0的个数
    C++中的Overload、Override和Overwrite
    C++中的空类与空结构体大小
    多线程编程之优先级翻转问题
    数据库原理之事务(二)
    数据库原理之事务(一)
    NoSQL之基础篇
  • 原文地址:https://www.cnblogs.com/poptest/p/5110629.html
Copyright © 2020-2023  润新知