You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 2, 2024. It is now read-only.
The PR is for the enhancement on the unit-tests of PlantDetailViewModel since we added the coroutines feature there.
TEST update:
shouldAddPlantToGarden(): Happy-Path to add one plant.
shouldCancelAddingPlantToGarden(): Cancel adding of one plant with calling cancel on the return handler of addPlantToGarden .
shouldCancelAddingPlantToGardenByViewModel(): Cancel adding of one plant with calling cancel on the view-model.
Based on this TEST update:
Refactoring, addPlantToGarden() which can return Job handler regard of the reason that the client codes can cancel adding action separately and flexibly instead only calling cancel of view-model.
Hmmm... I'm getting an error when I try to run this?
$ adb shell am instrument -w -r -e debug false -e class 'com.google.samples.apps.sunflower.viewmodels.PlantDetailViewModelTest' com.google.samples.apps.sunflower.test/androidx.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787 SQLITE_CONSTRAINT_FOREIGNKEY)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:796)
at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
at androidx.sqlite.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:51)
at androidx.room.EntityInsertionAdapter.insertAndReturnId(EntityInsertionAdapter.java:114)
at com.google.samples.apps.sunflower.data.GardenPlantingDao_Impl.insertGardenPlanting(GardenPlantingDao_Impl.java:76)
at com.google.samples.apps.sunflower.data.GardenPlantingRepository$createGardenPlanting$2.invokeSuspend(GardenPlantingRepository.kt:29)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
Test running failed: Instrumentation run failed due to 'Process crashed.'```
adb shell am instrument -w -r -e debug false -e class 'com.google.samples.apps.sunflower.viewmodels.PlantDetailViewModelTest' com.google.samples.apps.sunflower.test/androidx.test.runner.AndroidJUnitRunner
@nic0lette 😢 but it's really strange, I try this ./gradlew check connectedCheck(can test with multi devices) eachtime for whole testing stuff, everything fine at my side. Have you pulled the latest codebase?
I tried running, however, the output is failed:
adb shell am instrument -w -r -e debug false -e class 'com.google.samples.apps.sunflower.viewmodels.PlantDetailViewModelTest' com.google.samples.apps.sunflower.test/androidx.test.runner.AndroidJUnitRunner
onError: commandError=true message=INSTRUMENTATION_FAILED: com.google.samples.apps.sunflower.test/androidx.test.runner.AndroidJUnitRunner
android.util.AndroidException: INSTRUMENTATION_FAILED: com.google.samples.apps.sunflower.test/androidx.test.runner.AndroidJUnitRunner
at com.android.commands.am.Instrument.run(Instrument.java:486)
at com.android.commands.am.Am.runInstrument(Am.java:194)
at com.android.commands.am.Am.onRun(Am.java:80)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:54)
at com.android.commands.am.Am.main(Am.java:50)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:340)
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.google.samples.apps.sunflower.test/androidx.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS_CODE: -1
I tried with a fresh copy of the code in a separate directory and applied this PR. When I run all of the tests, it works great! Thank you!
If, however, I only run the tests in PlantDetailViewModelTest, then it fails with the android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787 SQLITE_CONSTRAINT_FOREIGNKEY) exception above.
I kept digging, and if I only run shouldAddPlantToGarden, it also passes.
This file contains hidden or 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
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
None yet
3 participants
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.
The PR is for the enhancement on the unit-tests of
PlantDetailViewModelsince we added thecoroutinesfeature there.TEST update:
shouldAddPlantToGarden(): Happy-Path to add one plant.
shouldCancelAddingPlantToGarden(): Cancel adding of one plant with calling
cancelon the return handler ofaddPlantToGarden.shouldCancelAddingPlantToGardenByViewModel(): Cancel adding of one plant with calling
cancelon theview-model.Based on this TEST update:
Refactoring,
addPlantToGarden()which can returnJobhandler regard of the reason that the client codes cancanceladding action separately and flexibly instead only callingcancelofview-model.Whether you agree?
@tiembo @nic0lette @objcode