Permalink
Browse files

Merge pull request #13 from bieridee/robotium

Robotium tests
  • Loading branch information...
2 parents 4f1324c + a8e93df commit 2207fe8a6453f5dff4e129a7e42a786dae8013f0 @dbrgn dbrgn committed May 5, 2012
View
@@ -1,66 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>ch.hsr.bieridee</groupId>
+ <artifactId>bieridee-front-parent</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
- <parent>
<groupId>ch.hsr.bieridee</groupId>
- <artifactId>bieridee-front-parent</artifactId>
+ <artifactId>bieridee-front-it</artifactId>
<version>1.0-SNAPSHOT</version>
- </parent>
-
- <groupId>ch.hsr.bieridee</groupId>
- <artifactId>bieridee-front-it</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>apk</packaging>
- <name>bieridee-front - Integration tests</name>
-
- <dependencies>
- <dependency>
- <groupId>com.google.android</groupId>
- <artifactId>android</artifactId>
- </dependency>
- <dependency>
- <groupId>com.google.android</groupId>
- <artifactId>android-test</artifactId>
- </dependency>
- <dependency>
- <groupId>ch.hsr.bieridee</groupId>
- <artifactId>bieridee-front</artifactId>
- <type>apk</type>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>ch.hsr.bieridee</groupId>
- <artifactId>bieridee-front</artifactId>
- <type>jar</type>
- <version>1.0-SNAPSHOT</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>com.jayway.maven.plugins.android.generation2</groupId>
- <artifactId>maven-android-plugin</artifactId>
- <configuration>
- <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
- <assetsDirectory>${project.basedir}/assets</assetsDirectory>
- <resourceDirectory>${project.basedir}/res</resourceDirectory>
- <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
- <sdk>
- <platform>10</platform>
- </sdk>
- <undeployBeforeDeploy>true</undeployBeforeDeploy>
- </configuration>
- <extensions>true</extensions>
- </plugin>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <packaging>apk</packaging>
+ <name>bieridee-front - Integration tests</name>
+ <dependencies>
+ <dependency>
+ <groupId>com.google.android</groupId>
+ <artifactId>android</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.android</groupId>
+ <artifactId>android-test</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.hsr.bieridee</groupId>
+ <artifactId>bieridee-front</artifactId>
+ <type>apk</type>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.hsr.bieridee</groupId>
+ <artifactId>bieridee-front</artifactId>
+ <type>jar</type>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.jayway.android.robotium</groupId>
+ <artifactId>robotium-solo</artifactId>
+ <version>3.1</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.jayway.maven.plugins.android.generation2</groupId>
+ <artifactId>maven-android-plugin</artifactId>
+ <configuration>
+ <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
+ <assetsDirectory>${project.basedir}/assets</assetsDirectory>
+ <resourceDirectory>${project.basedir}/res</resourceDirectory>
+ <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
+ <sdk>
+ <platform>10</platform>
+ </sdk>
+ <deleteConflictingFiles>true</deleteConflictingFiles>
+ <undeployBeforeDeploy>true</undeployBeforeDeploy>
+ </configuration>
+ <extensions>true</extensions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
@@ -0,0 +1,105 @@
+package ch.hsr.bieridee.android.test;
+
+import android.content.Intent;
+import android.test.ActivityInstrumentationTestCase2;
+import ch.hsr.bieridee.android.activities.AboutScreenActivity;
+import ch.hsr.bieridee.android.activities.HomeScreenActivity;
+import ch.hsr.bieridee.android.activities.LoginScreenActivity;
+import ch.hsr.bieridee.android.config.Auth;
+import com.jayway.android.robotium.solo.Solo;
+
+public class HomeScreenActivityTest extends ActivityInstrumentationTestCase2<HomeScreenActivity> {
+
+ private Solo solo;
+
+ public HomeScreenActivityTest() {
+ super(HomeScreenActivity.class);
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ solo = new Solo(getInstrumentation(), getActivity());
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ solo.finishOpenedActivities();
+ super.tearDown();
+ }
+
+ /**
+ * Destroy and restart current activity.
+ */
+ private void restartActivity() {
+ Intent testIntent = new Intent(getActivity().getBaseContext(), HomeScreenActivity.class);
+ getActivity().finish();
+ getActivity().startActivity(testIntent);
+ }
+
+ /**
+ * Clear authentication information and restart activity.
+ */
+ private void testWithoutLogin() {
+ Auth.clearAuth();
+ this.restartActivity();
+ }
+
+ /**
+ * Set dummy authentication information and restart activity.
+ */
+ private void testWithLogin() {
+ Auth.setAuth("testuser", "testpass", true);
+ this.restartActivity();
+ }
+
+ /**
+ * Test basic parts of the activity.
+ */
+ public void testDashboardItems() {
+ this.testWithLogin();
+ assertTrue(solo.searchText("Bierliste"));
+ assertTrue(solo.searchText("Timeline"));
+ assertTrue(solo.searchText("Brauereien"));
+ assertTrue(solo.searchText("Profil"));
+ assertTrue(solo.searchText("Konsum"));
+ assertTrue(solo.searchText("Rating"));
+ }
+
+ /**
+ * Should display the home screen activity.
+ */
+ public void testLoggedIn() {
+ this.testWithLogin();
+ getInstrumentation().callActivityOnRestart(getActivity());
+ assertTrue(solo.searchText("Bieridee Dashboard"));
+ solo.assertCurrentActivity("Expected home screen activity to stay open.", HomeScreenActivity.class);
+ }
+
+ /**
+ * Should redirect to login view.
+ */
+ public void testLoggedOut() {
+ this.testWithoutLogin();
+ getInstrumentation().callActivityOnRestart(getActivity());
+ solo.assertCurrentActivity("Expected login activity to launch.", LoginScreenActivity.class);
+ }
+
+ public void testLogoutButton() {
+ this.testWithLogin();
+ assertTrue("Expected auth data to be available.", Auth.dataAvailable());
+ solo.assertCurrentActivity("Expected home screen activity to be active.", HomeScreenActivity.class);
+ solo.sendKey(Solo.MENU);
+ solo.clickOnText("Logout");
+ assertFalse("Expected auth data to be gone.", Auth.dataAvailable());
+ solo.assertCurrentActivity("Expected login activity to launch.", LoginScreenActivity.class);
+ }
+
+ public void testAboutButton() {
+ this.testWithLogin();
+ solo.assertCurrentActivity("Expected home screen activity to be active.", HomeScreenActivity.class);
+ solo.sendKey(Solo.MENU);
+ solo.clickOnText("Über");
+ solo.assertCurrentActivity("Expected about screen activity to launch.", AboutScreenActivity.class);
+ }
+}
@@ -65,23 +65,4 @@ public void run() {
assertEquals(testPassword, passwordInputAfter.getText().toString());
assertEquals(autologinEnabled, autologinInputAfter.isChecked());
}
-
-// public void testRegisterNewAccount() {
-// final TextView registrationLink = (TextView) activity.findViewById(ch.hsr.bieridee.android.R.id_loginscreen.registrationLink);
-// final String registrationScreenTitle = activity.getString(ch.hsr.bieridee.android.R.string.registrationscreen_title);
-//
-// activity.runOnUiThread(new Runnable() {
-//
-// public void run() {
-// registrationLink.performClick();
-//
-// }
-// });
-// Instrumentation instrumentation = this.getInstrumentation();
-//
-// Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(RegistrationScreenActivity.class.getName(), null, false);
-// Activity newActivity = instrumentation.waitForMonitorWithTimeout(monitor, 2);
-// assertEquals(registrationScreenTitle, newActivity.getTitle());
-// // activity.getTitle();
-// }
}

0 comments on commit 2207fe8

Please sign in to comment.