Permalink
Browse files

Initial version of unit test framework.

  • Loading branch information...
1 parent 32ceb78 commit 84b9bfefec4f8efdbd5fd90cd5e37097dd9e5309 @hdweiss hdweiss committed Mar 13, 2012
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.matburt.mobileorg.test"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="3" />
+
+ <instrumentation
+ android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.matburt.mobileorg" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+</manifest>
View
@@ -0,0 +1,18 @@
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked in 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=../mobileorg-android
View
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="MobileOrgTest" 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" />
+
+ <!-- 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 an env var"
+ unless="sdk.dir"
+ />
+
+
+<!-- extension targets. Uncomment the ones where you want to do custom work
+ in between standard targets -->
+<!--
+ <target name="-pre-build">
+ </target>
+ <target name="-pre-compile">
+ </target>
+
+ /* 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} */
+ <target name="-post-compile">
+ </target>
+-->
+
+ <!-- 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 not shown.
Binary file not shown.
@@ -0,0 +1,11 @@
+# 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 use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-15
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/hello" />
+
+</LinearLayout>
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="hello">Hello World!</string>
+ <string name="app_name">Mobileorg-android-testTest</string>
+
+</resources>
@@ -0,0 +1,60 @@
+package com.matburt.mobileorg.test;
+
+import com.jayway.android.robotium.solo.Solo;
+import com.matburt.mobileorg.Gui.Capture.EditActivity;
+
+import android.content.Context;
+import android.content.Intent;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.UiThreadTest;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+
+public class EditActivityTest extends
+ ActivityInstrumentationTestCase2<EditActivity> {
+
+ private EditActivity mActivity;
+ private Solo solo;
+ private TextView mTitleView;
+ private Spinner mTodoState;
+
+ public EditActivityTest() {
+ super(EditActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Intent intent = new Intent();
+ intent.putExtra("actionMode", EditActivity.ACTIONMODE_CREATE);
+ this.setActivityIntent(intent);
+ this.setActivityInitialTouchMode(false);
+ this.mActivity = this.getActivity();
+
+ this.mTitleView = (TextView) mActivity.findViewById(com.matburt.mobileorg.R.id.title);
+ this.mTodoState = (Spinner) mActivity.findViewById(com.matburt.mobileorg.R.id.todo_state);
+
+ this.solo = new Solo(getInstrumentation(), getActivity());
+ }
+
+ @UiThreadTest
+ public void testTitleSimple() {
+ final String titleTest = "Hej";
+ mTitleView.setText(titleTest);
+ assertEquals(titleTest, mTitleView.getText().toString());
+
+ // this.sendKeys("H E J");
+ }
+
+ @UiThreadTest
+ public void testTodo() {
+ String defaultTodo = mActivity.getSharedPreferences("", Context.MODE_PRIVATE).getString("defaultTodo", "");
+ assertEquals(defaultTodo, this.mTodoState.getSelectedItem().toString());
+ }
+
+ public void testTags() {
+ solo.clickOnMenuItem("Add Tag");
+ solo.setActivityOrientation(0);
+ }
+}
@@ -0,0 +1,66 @@
+package com.matburt.mobileorg.test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.test.AndroidTestCase;
+
+import com.matburt.mobileorg.Parsing.OrgDatabase;
+
+
+public class OrgDatabaseTest extends AndroidTestCase {
+
+ private Context context;
+ private OrgDatabase db;
+ private ArrayList<String> filenames;
+
+ @Override
+ protected void setUp() {
+ //this.context = new IsolatedContext(null, mContext);
+ this.context = getContext();
+ this.db = new OrgDatabase(context);
+ this.filenames = getFilenames();
+ }
+
+ public ArrayList<String> getFilenames() {
+ HashMap<String,String> files = db.getFiles();
+
+ ArrayList<String> filenames = new ArrayList<String>();
+
+ for(String filename: files.keySet())
+ filenames.add(filename);
+
+ return filenames;
+ }
+
+ public void testFileCursor() {
+ Cursor fileCursor = db.getFileCursor();
+ assertNotNull(fileCursor);
+ assertEquals(filenames.size() - 1, fileCursor.getCount());
+ }
+
+ public void testFilenames() {
+ for (String filename : filenames) {
+ long fileID = db.getFilenameId(filename);
+ String rFilename = db.getFilename(fileID);
+
+ assertEquals(filename, rFilename);
+ }
+ }
+
+ public void testAddAndRemoveFile() {
+ final String testFilename = "testfile";
+ int preFilesize = db.getFiles().size();
+ db.addOrUpdateFile(testFilename, testFilename, null, false);
+ assertEquals(preFilesize+1, db.getFiles().size());
+ db.removeFile(testFilename);
+ assertEquals(preFilesize, db.getFiles().size());
+ }
+
+ public void testFileChecksums() {
+ HashMap<String,String> fileChecksums = db.getFileChecksums();
+ assertEquals(filenames.size(), fileChecksums.size());
+ }
+}

0 comments on commit 84b9bfe

Please sign in to comment.