Skip to content

Instantly share code, notes, and snippets.

@ArunYogeshwaran
Created July 6, 2023 14:08
Show Gist options
  • Save ArunYogeshwaran/85c732948575540c92e302b4a7f5d5a0 to your computer and use it in GitHub Desktop.
Save ArunYogeshwaran/85c732948575540c92e302b4a7f5d5a0 to your computer and use it in GitHub Desktop.
Behavior-driven tests can be easily understood by someone who's familiar with the system requirements. They also serve as indirect documentation of the code being tested, and they help in reducing the size of a test method, as only one behavior is tested at any time, even though the method under test does many things.
fun playArtist(artist: Artist) {
if (artist != Artist.TAYLOR_SWIFT) {
return IllegalArgException()
}
addToRecentlyPlayed(artist)
player.play(artist.getRandomSong())
}
@Test
fun `play artist verify recently played list contains artist`() {
val artist = Artist.TAYLOR_SWIFT
val audioPlayer = getAudioPlayer()
audioPlayer.playArtister(artist)
assertThat(recentlyPlayedList.contains(artist)).isTrue()
}
@Test
fun `play artist verify current song belongs to the artist`() {
val artist = Artist.TAYLOR_SWIFT
val audioPlayer = getAudioPlayer()
audioPlayer.playArtister(artist)
assertThat(audioPlayer.getCurrentSong().artist).isEqualTo(TAYLOR_SWIFT)
}
@Test
@Throws(IllegalArgException)
fun `play with invalid artist expect IllegalArgException`() {
val artist = Artist.MJ
val audioPlayer = getAudioPlayer()
audioPlayer.playArtister(artist)
}
@Test
fun `play artist verify recently played list and audio player state`() {
val artist = Artist.TAYLOR_SWIFT
val audioPlayer = getAudioPlayer()
audioPlayer.playArtister(artist)
assertThat(recentlyPlayedList.contains(artist)).isTrue()
assertThat(audioPlayer.getCurrentSong().artist).isEqualTo(TAYLOR_SWIFT)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment