I'm using Robotium to do some simple UI tasks on my unit testing project. I noticed Solo being significantly slower, I dont kn开发者_如何转开发ow why. I'm new to it.
This code is done with Robotium:
solo.clearEditText(editTextLogin);
solo.clearEditText(editTextSenha);
solo.enterText(editTextLogin, "tecnico@mail.com");
solo.enterText(editTextSenha, "12345");
solo.clickOnButton(0);
This is done with native code:
m_Activity.runOnUiThread(new Runnable() {
@Override
public void run() {
editTextLogin.setText("tecnico@mail.com");
editTextSenha.setText("12345");
loginButton.performClick();
}
});
The code performed with Robotium is much slower when compared to the second one. I can figure easily that Robotium is actually mechanically doing all the stuff, while the native code is just setting values to objects, which can explain the difference, but my question best explained would be, when to use Robotium, the way it should be, the way the real performance gain can be achieved.
My apologize for any mistakes.
You should download the source code for robotium and debug through it. You'll see that there's a lot more going on under the hood. For example, here is a little snippet for clickonbutton:
public <T extends TextView> void clickOn(Class<T> viewClass, String nameRegex) {
final Pattern pattern = Pattern.compile(nameRegex);
waiter.waitForText(nameRegex, 0, TIMEOUT, true, true);
ArrayList<T> views = viewFetcher.getCurrentViews(viewClass);
views = RobotiumUtils.removeInvisibleViews(views);
T viewToClick = null;
for(T view : views){
if(pattern.matcher(view.getText().toString()).matches()){
viewToClick = view;
if(viewToClick.isShown())
break;
}
}
if (viewToClick != null) {
clickOnScreen(viewToClick);
} else if (scroller.scroll(Scroller.DOWN)){
clickOn(viewClass, nameRegex);
}else {
for (T view : views) {
Log.d(LOG_TAG, nameRegex + " not found. Have found: " + view.getText());
}
Assert.assertTrue(viewClass.getSimpleName() + " with the text: " + nameRegex + " is not found!", false);
}
}
It calls my attention you are so worried about test performance.
Android UI testing methods are quite complicated and leaves you with a test case that's hard to follow. Robotium is not focused on performance, it's focus in making an API accesible by developers to make their tests easier to write and read.
I wouldn't try to determine what's the most performant way to do a test. I would do it in Robotium, since it's easier to code and afterwards porting to native if necessary.
In my personal case I don't care Robotium making my tests slower. If that's the price I have to pay to avoid using the native UI testing tool, I am cool with that.
If the test takes too much time you can always run in your CI.
Try with different method as my experience of using
solo.clickOnButton("String")
and solo.clickOnButton(index)
also differ greatly.
as the first one seems to doing a lot of searching.
精彩评论