Created
July 6, 2023 13:55
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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