Last active
February 6, 2023 13:12
-
-
Save ArunYogeshwaran/b8b9e7fe40c3a9c049b91d96f7052638 to your computer and use it in GitHub Desktop.
An example of testing the interaction vs testing the state
This file contains hidden or 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 toggleFavoriteForJob(job: Job) { | |
if (job.isFavorite) { | |
cache.unfavorite(job) | |
} else { | |
cache.favorite(job) | |
} | |
} | |
// A unit test using interaction testing | |
fun `toggle favorite with already favorited job verify job is unfavorited`() { | |
// Test arrangements and setup | |
val job = getTestFavoriteJob() | |
jobOperations.toggleFavoriteForJob(job) | |
verify(cache).unfavorite(job) | |
} | |
// A unit test using state testing | |
fun `toggle favorite with already favorited job verify job is unfavorited`() { | |
// Test arrangements and setup | |
val job = getTestFavoriteJob() | |
jobOperations.toggleFavoriteForJob(job) | |
assertThat(cache.getJobWithId(job.id).isFavorite()).isFalse() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment