Created
July 6, 2023 14:08
-
-
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.
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
fun playArtist(artist: Artist) { | |
if (artist != Artist.TAYLOR_SWIFT) { | |
return IllegalArgException() | |
} | |
addToRecentlyPlayed(artist) | |
player.play(artist.getRandomSong()) | |
} |
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
@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) | |
} |
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
@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