How to Use robotium (1)

Source: Internet
Author: User

1. Create an android Project

This step is only suitable for beginners. If you have a certain foundation, you can skip this step and go directly to step 2.

1. New Project

2. Select the android project to go to

3. Enter the project name and click Next.

4. Click Next and enter the package name on the displayed page.

5. Click Finish to complete a simple Android project. The directory structure of the project is as follows:

6. Run the interface

Ii. Use of robotium

1. Download the JAR file of robotium

Download the required JAR file at the address below

Http://code.google.com/p/robotium/downloads/list

I downloaded a jar package of 4.0.

2. Create a test project

2. Select Android test project and select an existing project to test. In the project list below, select the project to be tested.

3. Enter the package name, select the SDK version, and click Finish to create the project. The directory structure of the test project is as follows:

4. Create a test class. After creating this class, import the JAR file of robotium we downloaded before to the project.

package com.android.hello.test;import com.android.hello.HelloActivity;import com.jayway.android.robotium.solo.Solo;import android.test.ActivityInstrumentationTestCase2;public class TestScript  extends ActivityInstrumentationTestCase2<HelloActivity>{private Solo mSolo;public TestScript() {super("com.android.hello", HelloActivity.class);// TODO Auto-generated constructor stub}public void setUp(){mSolo=new Solo(getInstrumentation(), getActivity());}public void testText(){boolean expected =true;System.out.println("mSolo============"+mSolo);boolean actual =mSolo.searchText("Hello") &&mSolo.searchText("World");assertEquals("The text  have not found", expected, actual);}}

The purpose of this test class is to check whether there are two texts in the main interface: Hello and world.

5. The test results are as follows:

Iii. Common Errors During use

1. the prompt "Java. Lang. noclassdeffounderror: COM/jayway/Android/robobench/Solo" is displayed.

The specific code is as follows:

java.lang.NoClassDefFoundError: com/jayway/android/robotium/solo/Soloat java.lang.Class.getDeclaredFields(Native Method)at java.lang.Class.getDeclaredFields(Class.java:647)at android.test.ActivityTestCase.scrubClass(ActivityTestCase.java:63)at android.test.ActivityInstrumentationTestCase2.tearDown(ActivityInstrumentationTestCase2.java:172)at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545)at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)Caused by: java.lang.ClassNotFoundException: com.jayway.android.robotium.solo.Soloat dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)at java.lang.ClassLoader.loadClass(ClassLoader.java:501)at java.lang.ClassLoader.loadClass(ClassLoader.java:461)... 13 more

I didn't find the solo class.

Solution

Right-click the hellotest project file ------- properties ----------- Java build path ----- libraries Delete the android dependencies and robotium-solo-4.0.jar inside and then re-import the robotium-solo-4.0.jar.

Select All --- OK on the order and export interface.

Click project option ------ Clean Project in the toolbar.

For example

 

 

2. a null pointer is reported, prompting that msolo is null.

Check that the setup method name is case sensitive. Otherwise, the code in the method will not be executed.

This article describes how to use robotium for white-box testing and how to use robotium for black-box testing. Stay tuned.

References:

Http://blog.csdn.net/brucezhang0/article/details/7449551

Http://code.google.com/p/robotium

 

 

 

 

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.