Robotium : Android JUnit test annotations

robotium

Annotations Available With Android JUnit Test:

Deprecated

Annotation type used to mark program elements that should no longer be used by programmers.

Documented

Defines a meta-annotation for indicating that an annotation is documented and considered part of the public API.

FlakyTest

This annotation can be used on an InstrumentationTestCase‘s test methods.

Inherited

Defines a meta-annotation for indicating that an annotation is automatically inherited.

JavascriptInterface

Annotation that allows exposing methods to JavaScript.

LargeTest

Marks a test that should run as part of the large tests.

MediumTest

Marks a test that should run as part of the medium tests.

Override

Annotation type used to mark methods that override a method declaration in a superclass.

RemoteViews.RemoteView

This annotation indicates that a subclass of View is alllowed to be used with the RemoteViews mechanism.

Retention

Defines a meta-annotation for determining the scope of retention for an annotation.

SmallTest

Marks a test that should run as part of the small tests.

Smoke

Marks a test that should run as part of the smoke tests.

Suppress

Use this annotation on test classes or test methods that should not be included in a test suite.

SuppressLint

Indicates that Lint should ignore the specified warnings for the annotated element.

SuppressWarnings

Annotation type used to indicate that the compiler should not issue the specified warnings for the marked program element.

Target

Defines a meta-annotation for determining what ElementTypes an annotation can be applied to.

TargetApi

Indicates that Lint should treat this type as targeting a given API level, no matter what the project target is.

TestTarget

This @interface was deprecated in API level 14. Obsolete

TestTargetClass

This @interface was deprecated in API level 14. Obsolete

UiThreadTest

This annotation can be used on an InstrumentationTestCase‘s test methods.

ViewDebug.CapturedViewProperty

This annotation can be used to mark fields and methods to be dumped when the view is captured.

ViewDebug.ExportedProperty

This annotation can be used to mark fields and methods to be dumped by the view server.

ViewDebug.FlagToString

Defines a mapping from a flag to a String.

ViewDebug.IntToString

Defines a mapping from an int value to a String.

Most Frequently Used Annotations Are:

@Smoke
@SmallTest
@MediumTest
@LargeTest
@FlakyTest

Running Test Scripts For Specified Annotations From cmd:

adb shell am instrument -w -e size small Testprojectpackagename/android.test.InstrumentationTestRunner

 

Replace small with medium or large to run test methods belonging to @MediumTest and @LargeTest respectively.

If Junit Jmeter is used for XML report generation purpose, then replace android.test.InstrumentationTestRunner with com.zutubi.android.junitreport.JUnitReportTestRunner

@FlakyTest : This annotation is used for Repeatation of certain test suites.

e.g: @FlakyTest(tolerance=2) ; Replace 2 with the number of times you want to repeat that test suite.

Example of Annotations:

@SmallTest

public void testloginFunction()

{

//Clears Login field

solo.clearEditText(0);

//clears password field

solo.clearEditText(1);

//Clicks on the link ‘Forgot Password’/after clicking link opens in the browser.

//solo.clickOnText(“Forgot Password?”);

//solo.waitForDialogToOpen();

}

@MediumTest

//Navigates to previous activity from Browser.

//solo.goBack();

//Clicks on Cancel Button.

solo.clickOnButton(“Cancel”);

//waits for the dialogBox to come seeking confirmation of cancel.

solo.waitForDialogToOpen();

//Clicks on ‘No’ button on the dialogBox.

solo.clickOnButton(“No”);

//clicks on ‘Log In Button/note:login and password fields are empty.

solo.clickOnButton(“Log In”);

//verifies “* Fields are Empty/Not in valid Format” text comes in

assertTrue(solo.searchText(“* Fields are Empty/Not in valid Format”));

//enters spaces to login field and clicks login button.

solo.enterText(0, ”  “);

solo.clickOnButton(“Log In”);

}