Writing factorized tests with datasets
We will now turn our attention to testing the Track
class. We will focus specifically on the different states a Track
class can have: STOPPED
, PLAYING
, and RECORDING
. For each one of these states, we want to make sure that adding SoundEvents
works only if we are in the proper state (RECORDING
).
To do so, we could write the following test functions:
testAddSoundEvent()
: This function puts theTrack
in theSTOPPED
state, callstrack.addSoundEvent(0)
, and checkstrack.soundEvents().size == 0
testAddSoundEvent()
: This function puts theTrack
in thePLAYING
state, callstrack.addSoundEvent(0),
and checkstrack.soundEvents().size == 0
testAddSoundEvent()
: This function puts theTrack
in theRECORDING
state, callstrack.addSoundEvent(0)
, and checkstrack.soundEvents().size == 1
As you can see, the logic is the same, we simply change the inputs and the desired outputs. To factorize...