Beruflich Dokumente
Kultur Dokumente
Introduction
What is Junit What is Robotium Tools used Creating a New Test Project Importing Robotium jar Creating a new Test Case Coding convention for JUnit Class
What is JUnit
JUnit is an open source framework designed for writing and running tests in Java programming language It is used too write and run repeatable tests
What is Robotium
Robotium is another testing framework It is designed for writing robust black box tests for Android Applications We can test multiple activities using Robotium The tests are robust The user needs a minimum knowledge about the way the tested application works.
Tools used
We need to import Robotium framework into the project It is used for a accessing graphical elements in a more simple and intuitive way The jar file can be found at
https://code.google.com/p/robotium/downloads/list
We used robotium-solo-4.3.1.jar
1. Import robotium-solo- 4.3.1.jar in the following way: TestProjectName -> right click-> Properties -> Java Builder Path -> Add External Jar
After creating the test project, in the existing empty package, we need to have a new Junit Test Case.
After the class is generated, it must be changed to work with Android Projects.
1.
2.
3.
4.
Name of the test class must end with Test Name of the method must begin with test Return type of a test method must be void Test method must not throw any exception Test method must have any parameter
This code will be modified to work for an Android Application. The changes that must be made are displayed in the next slide
Accesing elements
Click a Button
Radio Button
solo.clickOnRadioButton(0); // 0 indicates the first element of type Radio // Button existing in the layout
Check Box
solo.clickOnCheckBox(0);
Complete EditText
// text is actually the string that will //be offered as input for the Edit Text
solo.enterText(0, "text");
Accesing elements
This is a way in which we can access a spinner and select one of its
items (in this case the 3rd one)
View view1 = solo.getView(Spinner.class, 0); solo.clickOnView(view1); solo.scrollToTop(); // I put this in here so that it always keeps the list at // start select the 3rd item in the spinner solo.clickOnView(solo.getView(TextView.class, 2));
Accesing elements
There are 2 ways of accessing an element By id
EditText et = (EditText) solo.getView(com.rinf.mobile.rotemps.R.id.etName); solo.enterText(et, "text");
By position
solo.enterText(0, "text");
When creating a new test, usually we add the adnotation @SmallTest The test method must be named in the following way: testName(). If we dont put the keyword test before the actual name, it will not be recognized as a test and so it will be completely ignored.
Sample Assertions
Assertions are used to check conditions. Examples of Assertions:
Asserts that two Strings are equal. We can set a specific message for each test to have a small description of the condition to be checked
Running Tests
Right click on Project Name -> Run As -> Android JUnit Test If the test conditions are fulfilled, the JUnit box has the following appearance:
Running Tests
For a failed test we have the possibility of tracing which condition failed
Test the page Send CV Complete all the fields Press the Send button Check if a specific text is displayed The last requirement checks the content provider.
The test passes if information from the input corresponds to the information displayed on the second pace
Questions ?