views:

72

answers:

3

I've been playing around with .NET SpeechSynthesizer lately.

and I've got a method that takes in a string and creates a .wav file out of that string. but how do I unit test this method ?

seems to me like this situation is one in which unit testing cannot help you. am I right ?

+1  A: 

When code has side effects like that, its not a clean layer test, but you can definitely test the side effects. Write the result to your temp dir. Verify the file is actually written to. Verify the format by loading it as a wave file.

To verify whats actually in the WAV file, well you probably don't want to analyze the wave file directly. In that case your test needs to monitor what parameters are sent to the WAV generator, to verify they are as expected.

Frank Schwieterman
A: 

You got access to any speech recognition software ? You perhaps could try and train it to listen to the generated speech....?

Or you could at least check the format is correct and not a zero-byte file I guess...

You also might be able to get hold of (or generate them youself) statistical information about the expected length (within a certain error range) of the output file, given the input sentence, the speed of speech etc.

monojohnny
+2  A: 

What do you want to test here?

Does the .NET SpeechSynthesizer API write the wave file or does it output something to your code which writes the wave file?

Testing this is the same as testing any other dependency. First isolate it (thin & mockable wrapper arround the NET SpeechSynthesizer API). Then validate your code gives the wrapper what you think it should be given and acts on any returned data the way it should act. Leave testing the .NET SpeechSynthesizer API to someone else (the creators of the API).

Testing the wrapper is an intergration test (don't let the name stop you from doing it in a TDD manor if thats your thing), and you will likely have to be quite loose on what you validate ("Speak(string) causes the output file to grow"). But again you don't need to validate the API works.

mlk