mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Use temporary database for tests
This commit is contained in:
@@ -8,6 +8,10 @@ android {
|
|||||||
applicationId "org.isoron.uhabits"
|
applicationId "org.isoron.uhabits"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
|
|
||||||
|
buildConfigField "Integer", "databaseVersion", "12"
|
||||||
|
buildConfigField "String", "databaseFilename", "\"uhabits.db\""
|
||||||
|
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +39,6 @@ dependencies {
|
|||||||
androidTestCompile 'com.android.support:support-annotations:23.1.1'
|
androidTestCompile 'com.android.support:support-annotations:23.1.1'
|
||||||
androidTestCompile 'com.android.support.test:runner:0.4.1'
|
androidTestCompile 'com.android.support.test:runner:0.4.1'
|
||||||
androidTestCompile 'com.android.support.test:rules:0.4.1'
|
androidTestCompile 'com.android.support.test:rules:0.4.1'
|
||||||
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
|
|
||||||
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
|
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
|
||||||
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
|
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,19 +35,13 @@
|
|||||||
android:maxSdkVersion="18"/>
|
android:maxSdkVersion="18"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name="com.activeandroid.app.Application"
|
android:name="HabitsApplication"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:backupAgent=".HabitsBackupAgent"
|
android:backupAgent=".HabitsBackupAgent"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/main_activity_title"
|
android:label="@string/main_activity_title"
|
||||||
android:theme="@style/AppBaseTheme">
|
android:theme="@style/AppBaseTheme">
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="AA_DB_NAME"
|
|
||||||
android:value="uhabits.db"/>
|
|
||||||
<meta-data
|
|
||||||
android:name="AA_DB_VERSION"
|
|
||||||
android:value="12"/>
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.google.android.backup.api_key"
|
android:name="com.google.android.backup.api_key"
|
||||||
android:value="AEdPqrEAAAAI6aeWncbnMNo8E5GWeZ44dlc5cQ7tCROwFhOtiw"/>
|
android:value="AEdPqrEAAAAI6aeWncbnMNo8E5GWeZ44dlc5cQ7tCROwFhOtiw"/>
|
||||||
|
|||||||
78
app/src/main/java/org/isoron/uhabits/HabitsApplication.java
Normal file
78
app/src/main/java/org/isoron/uhabits/HabitsApplication.java
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import com.activeandroid.ActiveAndroid;
|
||||||
|
import com.activeandroid.Configuration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class HabitsApplication extends Application
|
||||||
|
{
|
||||||
|
private boolean isTestMode()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getClassLoader().loadClass("org.isoron.uhabits.unit.models.HabitTest");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (final Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteDB(String databaseFilename)
|
||||||
|
{
|
||||||
|
File databaseFile = new File(String.format("%s/../databases/%s",
|
||||||
|
getApplicationContext().getFilesDir().getPath(), databaseFilename));
|
||||||
|
|
||||||
|
if(databaseFile.exists()) databaseFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate()
|
||||||
|
{
|
||||||
|
super.onCreate();
|
||||||
|
String databaseFilename = BuildConfig.databaseFilename;
|
||||||
|
|
||||||
|
if (isTestMode())
|
||||||
|
{
|
||||||
|
databaseFilename = "test.db";
|
||||||
|
deleteDB(databaseFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration dbConfig = new Configuration.Builder(this)
|
||||||
|
.setDatabaseName(databaseFilename)
|
||||||
|
.setDatabaseVersion(BuildConfig.databaseVersion)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
ActiveAndroid.initialize(dbConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTerminate()
|
||||||
|
{
|
||||||
|
ActiveAndroid.dispose();
|
||||||
|
super.onTerminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user