Repository Unit Tests #50

Merged
AmineB merged 38 commits from davidoskky/ReaderForSelfoss-multiplatform:repository_tests into master 2022-09-30 11:31:55 +00:00
Showing only changes of commit 41c951b659 - Show all commits

View File

@ -45,7 +45,14 @@ class RepositoryTest() {
@Test
fun `Instantiate repository`() {
AmineB marked this conversation as resolved
Review

This does not seem to do anything. Is it needed ?

This does not seem to do anything. Is it needed ?
Review

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 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.
Review

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.

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.
val repository = Repository(api, appSettingsService, connectivityStatus, db)
val success = try {
Repository(api, appSettingsService, connectivityStatus, db)
AmineB marked this conversation as resolved Outdated

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.

Same for all the other try catch in here.

Same for all the other try catch in here.

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.

I guess the repository should raise an exception during initialization then.

Yep. That should be the case.

> I guess the repository should raise an exception during initialization then. Yep. That should be the case.
true
} catch (e: Exception) {
false
AmineB marked this conversation as resolved Outdated

This does not seem to do anything. Is it needed ?

This does not seem to do anything. Is it needed ?

Same as above.

Same as above.
}
assertEquals(true, success)
}
@Test
@ -53,14 +60,28 @@ class RepositoryTest() {
every { appSettingsService.getApiVersion() } returns -1
AmineB marked this conversation as resolved Outdated

This does not seem to do anything. Is it needed ?

This does not seem to do anything. Is it needed ?

Same as above.

Same as above.
every { connectivityStatus.isNetworkConnected } returns MutableStateFlow(false)
val repository = Repository(api, appSettingsService, connectivityStatus, db)
val success = try {
Repository(api, appSettingsService, connectivityStatus, db)
true
} catch (e: Exception) {
false
}
assertEquals(true, success)
}
@Test
fun `Instantiate repository with negative stats`() {
coEvery { api.stats() } returns SelfossModel.StatusAndData(success = true, data = SelfossModel.Stats(-100, -50, -20))
val repository = Repository(api, appSettingsService, connectivityStatus, db)
val success = try {
Repository(api, appSettingsService, connectivityStatus, db)
true
} catch (e: Exception) {
false
}
assertEquals(true, success)
}
@Test