Testing with android part i of ii
This presentation is the property of its rightful owner.
Sponsored Links
1 / 24

Testing with Android Part I of II PowerPoint PPT Presentation


  • 102 Views
  • Uploaded on
  • Presentation posted in: General

Testing with Android Part I of II. Android Testing Framework. Based on JUnit The Android JUnit extensions provide component-specific test case classes. . Android Testing Framework. Test suites are contained in test packages that are similar to main application packages.

Download Presentation

Testing with Android Part I of II

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Testing with android part i of ii

Testing with Android Part I of II


Android testing framework

Android Testing Framework

  • Based on JUnit

  • The Android JUnit extensions provide component-specific test case classes.


Android testing framework1

Android Testing Framework

  • Test suites are contained in test packages that are similar to main application packages.

  • The SDK tools for building and tests are available in Eclipse with ADT, and also in command-line form for use with other IDES.


Android testing framework2

Android Testing Framework

  • These tools get information from the project of the application under test and use this information to automatically create the build files, manifest file, and directory structure for the test package.

  • The SDK also provides monkeyrunner, an API testing devices with Python programs, and UI/Application Exerciser Monkey, a command-line tool for stress-testing UIs by sending pseudo-random events to a device.


Android testing framework3

Android Testing Framework


Junit

JUnit

  • You can use the JUnitTestCase class to do unit testing on a plain Java object.

  • TestCaseis also the base class for AndroidTestCase, which you can use to test Android-dependent objects.

  • Besides providing the JUnit framework, AndroidTestCase offers Android-specific setup, teardown, and helper methods.


Testing from eclipse with adt

Testing from Eclipse with ADT

ADT provides several features that help you set up and manage your testing environment effectively:

  • It lets you quickly create a test project and link it to the application under test.

  • It lets you quickly import the classes of the application under test.

  • It lets you create run configurations for your test package and include in them flags that are passed to the Android testing framework.

  • It lets you run your test package without leaving Eclipse.


Creating a test project

Creating a Test Project


Testing with android part i of ii

The class contains definitions for four methods:

  • HelloAndroidTest: This defines the constructor for the class. It is required by the Android testing framework.

  • setUp(): This overrides the JUnitsetUp() method. You use it to initialize the environment before each test runs.

  • testPreconditions(): This defines a small test that ensures the Hello, Android application starts up correctly.

  • testText(): This tests that what is displayed on the screen is the same as what is contained in the application's string resources. It is an example of a real unit test you would perform against an application's UI.


Creating the test case class

Creating the Test Case Class


Helloandroidtest java

HelloAndroidTest.java

package com.example.helloandroid.test;

import android.test.ActivityInstrumentationTestCase2;

import com.example.helloandroid.HelloAndroid;

public class HelloAndroidTest extends ActivityInstrumentationTestCase2<HelloAndroid> {

}


Constructor

Constructor

private HelloAndroidmActivity;

private TextViewmView;

private String resourceString;

public HelloAndroidTest() {

      super("com.example.helloandroid",HelloAndroid.class);

    }


Setup

setUp()

@Override

protected void setUp() throws Exception {

super.setUp();

mActivity = this.getActivity();

mView = (TextView) mActivity.findViewById (com.example.helloandroid.R.id.textview);

resourceString = mActivity.getString (com.example.helloandroid.R.string.hello);

}


Adding a preconditions test

Adding a preconditions test

A preconditions test checks the initial application conditions prior to executing other tests.

public void testPreconditions() {

assertNotNull(mView);

}


Adding a unit test

Adding a unit test

public void testText() {

assertEquals(resourceString,(String)mView.getText());

}


Finished class 1

Finished Class - 1

package com.example.helloandroid.test;

import com.example.helloandroid.HelloAndroid;

import android.test.ActivityInstrumentationTestCase2;

import android.widget.TextView;

public class HelloAndroidTest extends ActivityInstrumentationTestCase2<HelloAndroid> {

private HelloAndroidmActivity; // the activity under test

private TextViewmView; // the activity's TextView (the only view)

private String resourceString;

public HelloAndroidTest() {

super("com.example.helloandroid", HelloAndroid.class);

}

}


Finished class

Finished Class

@Override

protected void setUp() throws Exception {

super.setUp();

mActivity = this.getActivity();

mView = (TextView) mActivity.findViewById(com.example.helloandroid.R.id.textview);

resourceString = mActivity.getString(com.example.helloandroid.R.string.hello);

}

public void testPreconditions() {

assertNotNull(mView);

}

public void testText() {

assertEquals(resourceString,(String)mView.getText());

}

}


Running tests

Running Tests

  • When you run a test package in Eclipse with ADT, the output appears in the Eclipse JUnit view.

  • You can run the entire test package or one test case class. To do run tests, Eclipse runs the adb command for running a test package, and displays the output, so there is no difference between running tests inside Eclipse and running them from the command line.


  • Login