Robotium is a test framework for automated testing of Android applications by black box method. Robotium allows you to create scripts for functional, system and acceptance testing.
Simple test on Robotium:
Before creating a test, create a new project in Eclipse IDE:
- Create a new project (File->New->Java Project)
- Create a package under this project (com.tests)
- Add robotium-solo-xxx.jar to Java Build Path
- Right click on the project
- Click “Properties”
- Click Java Build Path
- Click Libraries
- Click Add External Libraries
- Select robotium-solo-xxx.jar
- Create test class under the package from step 2 (Example.java)
So, let’s start writing our first test:
public class Example extends ActivityInstrumentationTestCase2declare our class private Solo solo; declare a class object Solo{
public EditorTest() { super(“com.test.editor”, EditorActivity.class); }declare the constructor of our class
@Override public void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity()); } @Override public void tearDown() throws Exception { try { solo.finalize(); } catch (Throwable e) { e.printStackTrace(); } getActivity().finish(); super.tearDown(); }
override setUp() and tearDown(), which will be run before performing the test and after the test, respectively.
public void testSomething() throws Exception { solo.sendKey(Solo.MENU); solo.clickOnText(“More”); solo.clickOnText(“Preferences”); solo.clickOnText(“Edit”); Assert.assertTrue(solo.searchText(“hello”)); }
directly the actual test.
As we can see, everything is simple!
Useful links: http://code.google.com/p/robotium/