Repository Unit Tests #50
@ -46,14 +46,10 @@ class RepositoryTest() {
|
||||
|
||||
@Test
|
||||
AmineB marked this conversation as resolved
|
||||
fun `Instantiate repository`() {
|
||||
val success = try {
|
||||
Repository(api, appSettingsService, connectivityStatus, db)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
Repository(api, appSettingsService, connectivityStatus, db)
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
As mentionnend in my previous comment. The try catch must be in the code, not in the unit test.
As mentionnend in my previous comment. The try catch must be in the code, not in the unit test.
AmineB
commented
Same for all the other try catch in here. Same for all the other try catch in here.
davidoskky
commented
I'm not sure how I would implement this test otherwise, I guess the repository should raise an exception during initialization then. I'm not sure how I would implement this test otherwise, I guess the repository should raise an exception during initialization then.
AmineB
commented
Yep. That should be the case. > I guess the repository should raise an exception during initialization then.
Yep. That should be the case.
|
||||
|
||||
assertEquals(true, success)
|
||||
coVerify(exactly = 1) { api.version() }
|
||||
coVerify(exactly = 1) { api.stats() }
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
This does not seem to do anything. Is it needed ? This does not seem to do anything. Is it needed ?
davidoskky
commented
Same as above. Same as above.
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -61,28 +57,23 @@ class RepositoryTest() {
|
||||
every { appSettingsService.getApiVersion() } returns -1
|
||||
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
|
||||
|
||||
val success = try {
|
||||
Repository(api, appSettingsService, connectivityStatus, db)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
Repository(api, appSettingsService, connectivityStatus, db)
|
||||
AmineB marked this conversation as resolved
Outdated
AmineB
commented
This does not seem to do anything. Is it needed ? This does not seem to do anything. Is it needed ?
davidoskky
commented
Same as above. Same as above.
|
||||
|
||||
assertEquals(true, success)
|
||||
coVerify(exactly = 0) { api.version() }
|
||||
coVerify(exactly = 0) { api.stats() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Instantiate repository with negative stats`() {
|
||||
coEvery { api.stats() } returns SelfossModel.StatusAndData(success = true, data = SelfossModel.Stats(-100, -50, -20))
|
||||
|
||||
val success = try {
|
||||
Repository(api, appSettingsService, connectivityStatus, db)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
val repository = Repository(api, appSettingsService, connectivityStatus, db)
|
||||
|
||||
assertEquals(true, success)
|
||||
assertEquals(0, repository.badgeAll)
|
||||
assertEquals(0, repository.badgeStarred)
|
||||
assertEquals(0, repository.badgeUnread)
|
||||
coVerify(exactly = 1) { api.version() }
|
||||
coVerify(exactly = 1) { api.stats() }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user
This does not seem to do anything. Is it needed ?
The test can fail if the repository initialization generates an error; this is just a very general case to identify if something in the repository initialization is broken.
All other tests would fail as well, but this will give you certainty that the point of failure is in the initialization.
The way I understand your comment is that sometimes, the repository can fail an throw an error.
This should not be handled in a unit test, but handled in the code.
The exception should be catched and handled there.
You can keep your tests, but the call should return something, and the tests should actually test something.
Same for the three following tests.