Skip to content

Instantly share code, notes, and snippets.

@ArunYogeshwaran
Last active February 5, 2023 22:03
Show Gist options
  • Save ArunYogeshwaran/cf732dc584caf79f8007ac510c683dd2 to your computer and use it in GitHub Desktop.
Save ArunYogeshwaran/cf732dc584caf79f8007ac510c683dd2 to your computer and use it in GitHub Desktop.
Example of a unit test with a descriptive name
// Unit under test
fun fetchJobs(user: User) : List<Job> {
if (user.isRegistered()) {
return emptyList()
} else {
val jobs = jobsApi.getJobs(user)
return jobs
}
}
// A test with a non-descriptive name
@Test
fun `test fetch jobs`() {
// Test arrangements and setup
val user = getRegisteredTestUser()
val jobs = jobsSource.fetchJobs(user)
assertThat(jobs).isEqualTo(expectedJobs)
}
// A test with a descriptive name
@Test
fun `fetch jobs with registered user verify valid list returned`() {
// Test arrangements and setup
val user = getRegisteredTestUser()
val jobs = jobsSource.fetchJobs(user)
assertThat(jobs).isEqualTo(expectedJobs)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment