-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature run test under different package #1834
Open
Amejia481
wants to merge
19
commits into
development
Choose a base branch
from
feature-run_test_under_different_package
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
bb5dff6
Adding DBFlow processor v 3.0.1 as a project dependency
Amejia481 c762989
Modifying DBFlow processor to also generate a inMemory db for testing
Amejia481 6efb641
Removing staging build variant
Amejia481 7abec10
Changing testInstrumentationRunner to allow inMemory a Database.
Amejia481 cf5c6a3
Changing testInstrumentationRunner for strategy pattern
Amejia481 cb47cf0
Deleting dbflow annotation processor source files
Amejia481 1cd03b9
Adding dbflow annotation processor as a git submodule
Amejia481 6204099
Adding a JUnit rule for resetting state of the DBFlow database per each
Amejia481 360d6df
Merge branch 'development' into feature-run_test_under_different_package
idelcano 3f1989d
working
idelcano 8c000b7
fix some tests
idelcano 44f9244
fix test
idelcano be85172
removed reset() method and use destroy() to avoid remove the app data…
idelcano 9142245
get version from gradle instead use android context and package manager
idelcano 577569c
fix constructor methods order
idelcano 5f62eff
fix getContext and getTargetContext. The target context affects the n…
idelcano d89714e
Merge branch 'development' into feature-run_test_under_different_package
idelcano 8d8feb0
fix tests
idelcano 77d8cbc
refactor common code
idelcano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/src/androidTest/java/org/eyeseetea/malariacare/DatabaseHolderProviderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.eyeseetea.malariacare; | ||
|
||
|
||
import com.raizlabs.android.dbflow.config.DatabaseHolder; | ||
import com.raizlabs.android.dbflow.config.EyeSeeTeaInMemoryGeneratedDatabaseHolder; | ||
|
||
public class DatabaseHolderProviderStrategy implements | ||
EyeSeeTeaApplication.IDatabaseHolderProviderStrategy { | ||
@Override | ||
public Class<? extends DatabaseHolder> provide() { | ||
return EyeSeeTeaInMemoryGeneratedDatabaseHolder.class; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/src/androidTest/java/org/eyeseetea/malariacare/InMemoryDBFlowDataBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.eyeseetea.malariacare; | ||
|
||
import android.support.test.InstrumentationRegistry; | ||
|
||
import com.raizlabs.android.dbflow.config.FlowConfig; | ||
import com.raizlabs.android.dbflow.config.FlowManager; | ||
|
||
import org.junit.rules.ExternalResource; | ||
|
||
/*This test Rules creates a new clean instance of the DBFlow database per each @Test method | ||
that you have, if you change anything in database(insert,delete and update), | ||
it will be clean up when the next @Test methods runs. | ||
For instance, if you have the following: | ||
|
||
@Test | ||
public void test1(){ | ||
QuestionDB question1 = new QuestionDB(); | ||
question1.save(); //After this line id_question | ||
// It's going to be equals to 1 | ||
} | ||
|
||
@Test | ||
public void test2(){ | ||
QuestionDB question2 = new QuestionDB(); | ||
question2.save(); //After this line id_question | ||
// it's still equals to 1 | ||
// The InMemoryDBFlowDataBase cleans up for you. | ||
} | ||
*/ | ||
public class InMemoryDBFlowDataBase extends ExternalResource { | ||
|
||
@Override | ||
protected void after() { | ||
|
||
FlowManager.reset(); | ||
|
||
initDBFlowDB(); | ||
} | ||
|
||
private void initDBFlowDB() { | ||
DatabaseHolderProviderStrategy databaseStrategy = new DatabaseHolderProviderStrategy(); | ||
FlowConfig flowConfig = new FlowConfig | ||
.Builder(InstrumentationRegistry.getTargetContext()) | ||
.addDatabaseHolder(databaseStrategy.provide()) | ||
.build(); | ||
FlowManager.init(flowConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,11 @@ | |
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
import static org.eyeseetea.malariacare.configurationimporter | ||
.ConstantsMetadataConfigurationImporterTest.COUNTRIES_VERSION; | ||
import static org.eyeseetea.malariacare.configurationimporter | ||
.ConstantsMetadataConfigurationImporterTest.COUNTRIES_VERSION_V2; | ||
import static org.eyeseetea.malariacare.configurationimporter | ||
.ConstantsMetadataConfigurationImporterTest.TZ_CONFIG_ANDROID_2_0_JSON; | ||
import static org.eyeseetea.malariacare.configurationimporter.ConstantsMetadataConfigurationImporterTest.COUNTRIES_VERSION; | ||
import static org.eyeseetea.malariacare.configurationimporter.ConstantsMetadataConfigurationImporterTest.COUNTRIES_VERSION_V2; | ||
import static org.eyeseetea.malariacare.configurationimporter.ConstantsMetadataConfigurationImporterTest.TZ_CONFIG_ANDROID_2_0_JSON; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
|
||
import org.eyeseetea.malariacare.data.authentication.CredentialsReader; | ||
import org.eyeseetea.malariacare.data.database.model.CountryVersionDB; | ||
import org.eyeseetea.malariacare.data.database.model.OptionDB; | ||
|
@@ -20,18 +16,16 @@ | |
import org.eyeseetea.malariacare.data.database.model.QuestionDB; | ||
import org.eyeseetea.malariacare.data.database.model.QuestionOptionDB; | ||
import org.eyeseetea.malariacare.data.database.utils.Session; | ||
import org.eyeseetea.malariacare.data.database.utils.populatedb.PopulateDB; | ||
import org.eyeseetea.malariacare.data.server.CustomMockServer; | ||
import org.eyeseetea.malariacare.data.sync.factory.ConverterFactory; | ||
import org.eyeseetea.malariacare.data.sync.importer.metadata.configuration | ||
.MetadataConfigurationApiClient; | ||
import org.eyeseetea.malariacare.data.sync.importer.metadata.configuration | ||
.MetadataConfigurationDBImporter; | ||
import org.eyeseetea.malariacare.data.sync.importer.metadata.configuration.MetadataConfigurationApiClient; | ||
import org.eyeseetea.malariacare.data.sync.importer.metadata.configuration.MetadataConfigurationDBImporter; | ||
import org.eyeseetea.malariacare.domain.entity.Credentials; | ||
import org.eyeseetea.malariacare.domain.entity.Program; | ||
import org.eyeseetea.malariacare.network.retrofit.BasicAuthInterceptor; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
@@ -44,9 +38,11 @@ public class MetadataConfigurationDBImporterShould { | |
|
||
private final Program program = new Program("T_TZ", "low6qUS2wc9"); | ||
|
||
@Rule | ||
public InMemoryDBFlowDataBase mInMemoryDBFlowDataBase = new InMemoryDBFlowDataBase(); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
PopulateDB.wipeDataBase(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now, I can delete this line, because the rule is keeping the state of the DB separated, between |
||
CredentialsReader credentialsReader = CredentialsReader.getInstance(); | ||
Session.setCredentials( | ||
new Credentials("/", credentialsReader.getUser(), | ||
|
@@ -125,7 +121,7 @@ private void whenConfigFilesAreParsed() throws Exception { | |
MetadataConfigurationDBImporter importer = new MetadataConfigurationDBImporter( | ||
apiClient, ConverterFactory.getQuestionConverter() | ||
); | ||
|
||
importer.hasToUpdateMetadata(program); | ||
importer.importMetadata(program); | ||
} | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/eyeseetea/malariacare/DatabaseHolderProviderStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.eyeseetea.malariacare; | ||
|
||
|
||
import com.raizlabs.android.dbflow.config.DatabaseHolder; | ||
import com.raizlabs.android.dbflow.config.EyeSeeTeaGeneratedDatabaseHolder; | ||
|
||
public class DatabaseHolderProviderStrategy implements | ||
EyeSeeTeaApplication.IDatabaseHolderProviderStrategy { | ||
@Override | ||
public Class<? extends DatabaseHolder> provide() { | ||
return EyeSeeTeaGeneratedDatabaseHolder.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an example of using the JUnit rule that I mentioned in the PR.