Skip to content

Commit

Permalink
- Add test project back in. Not working with the build right now, TODO.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinberry committed Mar 26, 2013
1 parent becf9ec commit 960d93c
Show file tree
Hide file tree
Showing 23 changed files with 1,134 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,3 +11,4 @@ tmp/
local.properties local.properties
target/ target/
resilience-local.properties resilience-local.properties
*.iml
Expand Up @@ -26,7 +26,7 @@ private void initialiseParse() {


Log.d(LOG_TAG, "Connecting to parse using " + appKey + " application key and " + clientKey + " client key"); Log.d(LOG_TAG, "Connecting to parse using " + appKey + " application key and " + clientKey + " client key");


Parse.initialize(this, appKey, clientKey); // Parse.initialize(this, appKey, clientKey);
} }


private void setDefaultPreferences() { private void setDefaultPreferences() {
Expand Down

This file was deleted.

Expand Up @@ -2,7 +2,6 @@


import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import au.com.dius.resilience.bootstrap.ResilienceModule;
import au.com.dius.resilience.model.Incident; import au.com.dius.resilience.model.Incident;
import au.com.dius.resilience.model.Photo; import au.com.dius.resilience.model.Photo;
import au.com.dius.resilience.persistence.repository.RepositoryCommandResult; import au.com.dius.resilience.persistence.repository.RepositoryCommandResult;
Expand All @@ -12,14 +11,13 @@
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.util.Modules; import com.google.inject.util.Modules;
import com.xtremelabs.robolectric.Robolectric; import com.xtremelabs.robolectric.Robolectric;
import junit.framework.Assert;
import roboguice.RoboGuice; import roboguice.RoboGuice;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;


import static com.sun.tools.internal.ws.wsdl.parser.Util.fail;

public class TestHelper { public class TestHelper {
public static RepositoryCommand<String> createRepositoryCommand() { public static RepositoryCommand<String> createRepositoryCommand() {
return new RepositoryCommand<String>() { return new RepositoryCommand<String>() {
Expand Down Expand Up @@ -83,7 +81,7 @@ public static void assertContainsIntents(List<Intent> intents, String intentActi
return; return;
} }
} }
fail("Did not find intent in list " + intentAction); Assert.fail("Did not find intent in list " + intentAction);
} }


public static void overrideRoboguiceModule(Module module) { public static void overrideRoboguiceModule(Module module) {
Expand Down
24 changes: 24 additions & 0 deletions resilience-test/AndroidManifest.xml
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="au.com.dius.resilience.tests"
android:versionCode="1"
android:versionName="1.0">

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17"/>
<!-- We add an application tag here just so that we can indicate that
this package needs to link against the android.test library,
which is needed when building test cases. -->
<application>
<uses-library android:name="android.test.runner"/>
</application>
<!--
This declares that this application uses the instrumentation test runner targeting
the package of au.com.dius.resilience. To run the tests use the command:
"adb shell am instrument -w au.com.dius.resilience.tests/android.test.InstrumentationTestRunner"
-->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="au.com.dius.resilience"
android:label="Tests for au.com.dius.resilience"/>
</manifest>
18 changes: 18 additions & 0 deletions resilience-test/ant.properties
@@ -0,0 +1,18 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

tested.project.dir=../resilience-android/resilience-app
92 changes: 92 additions & 0 deletions resilience-test/build.xml
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="resilience_test" default="help">

<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties"/>

<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties"/>

<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env"/>
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME"/>
</condition>

<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties"/>

<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>

<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true"/>

<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml"/>

</project>
Binary file added resilience-test/libs/robotium-solo-3.5.1.jar
Binary file not shown.
20 changes: 20 additions & 0 deletions resilience-test/proguard-project.txt
@@ -0,0 +1,20 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
14 changes: 14 additions & 0 deletions resilience-test/project.properties
@@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-16
@@ -0,0 +1,62 @@
package au.com.dius.resilience.test;

import android.test.ActivityInstrumentationTestCase2;
import android.widget.SeekBar;
import com.jayway.android.robotium.solo.Solo;

import java.util.concurrent.CountDownLatch;

/**
* @author georgepapas
*/
public abstract class AbstractResilienceActivityTestCase<T extends android.app.Activity> extends ActivityInstrumentationTestCase2<T> {

public static final String LOG_TAG = AbstractResilienceActivityTestCase.class.getName();

protected Solo solo;

private ResilienceTestActions testActions;

protected void beforeTest() {
}

protected void afterTest() {
}

public AbstractResilienceActivityTestCase(Class<T> activityClass) {
super(activityClass);
testActions = new ResilienceTestActions(this);
}

protected String getString(int id) {
return testActions.getString(id);
}

protected void setProgressBar(final SeekBar seekbar, final int progress) {
final CountDownLatch latch = new CountDownLatch(1);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
seekbar.setProgress(progress);
latch.countDown();
}
});

try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

@Override
protected void setUp() {
testActions.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}

@Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
}
}
@@ -0,0 +1,29 @@
package au.com.dius.resilience.test;

import android.content.Context;
import android.test.InstrumentationTestCase;

/**
* For running instrumentation tests which do not have an activity bound to them.
*/
public class AbstractResilienceTestCase extends InstrumentationTestCase {

private ResilienceTestActions testActions;

public AbstractResilienceTestCase() {
testActions = new ResilienceTestActions(this);
}

@Override
public void setUp() {
testActions.setUp();
}

public Context getContext() {
return getInstrumentation().getContext();
}

protected String getString(int id) {
return testActions.getString(id);
}
}
@@ -0,0 +1,48 @@
package au.com.dius.resilience.test;

import android.content.Context;
import android.preference.PreferenceManager;
import android.test.InstrumentationTestCase;
import android.util.Log;
import au.com.dius.resilience.persistence.repository.impl.PreferenceAdapter;
import au.com.dius.resilience.test.util.ParseTestUtils;

import static android.content.Context.MODE_PRIVATE;

/**
* For sharing test helper functionality across AbstractResilience*TestCases.
*/
public class ResilienceTestActions {

private InstrumentationTestCase test;
private static final String LOG_TAG = ResilienceTestActions.class.getName();

public ResilienceTestActions(InstrumentationTestCase instrumentation) {
this.test = instrumentation;
}

public void setUp() {
Log.d(LOG_TAG, "Preparing for test " + Thread.currentThread().getName());
test.getInstrumentation().waitForIdleSync();
reinitialiseSharedPreferences();

// ParseTestUtils.setUp(test.getInstrumentation().getTargetContext());
// ParseTestUtils.dropAll(test.getInstrumentation());
}

private void reinitialiseSharedPreferences() {
Context application = test.getInstrumentation().getTargetContext();
application.getSharedPreferences(PreferenceAdapter.PREFERENCES_FILE_COMMON, MODE_PRIVATE)
.edit().clear().commit();
application.getSharedPreferences(PreferenceAdapter.PREFERENCES_FILE_DEFAULT, MODE_PRIVATE)
.edit().clear().commit();
PreferenceManager.setDefaultValues(application, PreferenceAdapter.PREFERENCES_FILE_COMMON,
MODE_PRIVATE, au.com.dius.resilience.R.xml.common_preferences, true);
PreferenceManager.setDefaultValues(application, PreferenceAdapter.PREFERENCES_FILE_DEFAULT, MODE_PRIVATE,
au.com.dius.resilience.R.xml.user_preferences, true);
}

public String getString(int id) {
return test.getInstrumentation().getContext().getString(id);
}
}

0 comments on commit 960d93c

Please sign in to comment.