Reputation: 732
I've been trying to get the Robotium tester to work for the Android project in libGDX, but got some problems. First I want to test my games buttons (that are imageButtons), but for that I need the imageButton index in Android.
How can I get that?
My button is in the main project:
ImageButtonStyle style = new ImageButtonStyle();
style.imageUp = buttonsImagesUp;
style.imageDown = buttonsImagesDown;
ImageButton newgameButton = new ImageButton(style);
newgameButton.setPosition(425,330);
This is the button I would like to test in JUnit.
My JUnit code:
public class ButtonTest extends ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
@SuppressWarnings("deprecation")
public ButtonTest() {
super("com.me.myGame", MainActivity.class);
}
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
public void testMenu(){
solo.assertCurrentActivity("First menu selected", MainActivity.class);
solo.clickOnImageButton(index); //need index
}
}
My game is set up like this: First there is the main Game class that handles the resources and sets the first screen to the main Menu:
@Override
public void create() {
playSound = userPref.getBoolean("playSounds");
setScreen(mainMenuScreen);
}
And after this it goes to the MainMenuScreen.js and thats were the buttons are that I want to test with JUnit
Upvotes: 2
Views: 607
Reputation: 25177
Robotium's idea of an ImageButton
is very, very different from Libgdx. Robotium is expecting an image button that is defined as part of the standard Android UI infrastructure (see Android ImageButton
). The Libgdx ImageButton
is a Java object with an OpenGL texture reference (see Libgdx ImageButton
). From the Android UI infrastructure point of view, a Libgdx app is just a full-screen OpenGL view, and has very little meta-data for Robotium to use.
You may be able to use the raw "clickOnScreen" infrastructure, but you will have to manually compute and track the location of your buttons on the screen. Additionally, I would be surprised if Robotium did not contain other dependencies on the Android UI infrastructure that are not there in a Libgdx app.
Upvotes: 2