-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the problem
JUnit assertions have not been designed with Kotlin in mind.
Describe the solution
On the other hand, Kotlin's test framework make use of Kotlin's strenghts and we could benefit from it.
-
better error messages by default
Assert.assertTrue(item is TopicUiState.Success) // java.lang.AssertionError
vs
kotlin.test.assertIs<TopicUiState.Success>(item) // Expected value to be of type <com.google.samples.apps.nowinandroid.feature.topic.TopicUiState.Success>, actual <class com.google.samples.apps.nowinandroid.feature.topic.TopicUiState$Error>.
-
better type inference
// This code would produce an error because `getCurrentFollowedTopics` return type is `Set<String>?` kotlin.test.assertEquals(emptySet<Int>(), userDataRepository.getCurrentFollowedTopics()) // Instead, let the type inference do it's job by omiting the type altogether assertEquals(emptySet(), userDataRepository.getCurrentFollowedTopics())
-
smart cast
val item = viewModel.topicUiState.value assertIs<TopicUiState.Success>(item) // Now item can be used as a TopicUiState.Success
Additional context
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request