Skip to content

Instantly share code, notes, and snippets.

@ArunYogeshwaran
Created July 6, 2023 13:55
Show Gist options
  • Save ArunYogeshwaran/e582d685bd388ce8e8c6f24b1a917a46 to your computer and use it in GitHub Desktop.
Save ArunYogeshwaran/e582d685bd388ce8e8c6f24b1a917a46 to your computer and use it in GitHub Desktop.
The example below shows a simple system that fetches jobs for a user who can be either registered or unregistered.
// 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