Comments (3)
Nevermind, found the issue. Fixed it by creating the testObserver before calling loadArticle like so:
Test
fun testLoadArticle_ErrorState() {
whenever(getNewsUseCase.getNewsArticleById(anyInt()))
.thenReturn(Observable.just(IccResult.Failure(IccError.Unknown(Exception()))))
val testObserver = articleViewModel.screenState.test()
articleViewModel.loadArticle(1)
testObserver
.assertValueHistory(
ScreenState.loading(true),
ScreenState.loading(false),
ScreenState.empty(),
ScreenState.error(R.string.error_loading_failed_message))
verify(getNewsUseCase).getNewsArticleById(anyInt())
}
from livedata-testing.
Hello, yes that would be my suggestion as well.
The problem is that TestObserver
has no idea about the previous values on LiveData
if he was not observing before.
Since in the first code version during articleViewModel.loadArticle(1)
there is no observer and we test afterwards, observer receives only the last value.
Thanks for using the library and if there is more feedback let me know.
from livedata-testing.
Yes, i noticed that afterwards. Thank you. Library is very good :)
from livedata-testing.
Related Issues (20)
- Readme with Philosophy HOT 1
- Medium post HOT 1
- Test results uploading on Circle CI not finding the file HOT 3
- Use androidx namespace HOT 1
- Await values
- Add Managing Lifecycle State HOT 1
- Unable to import TestObserver class! HOT 2
- cannot access test() from live data HOT 3
- Add possibility to assert value as they come through onChanged HOT 2
- Evaluate and maybe add assertValues and assertValuesOnly
- Evaluate and maybe add assertOf(Consumer<TestObserver>) HOT 1
- How to instantiate a viewmodel which extends AndroidViewModel class HOT 3
- Strict dependency on androidx 2.0.0 HOT 4
- Proposal : add assertValueHistory for list of predicates, not values HOT 3
- Consider matching function names/behaviour to RxJava TestObserver HOT 2
- Testing LiveData Transformations causes NPE HOT 3
- Update the project HOT 1
- Migrate to Maven Central HOT 8
- Add awaitValuesCount(Int)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from livedata-testing.