I would like to write unit tests for some classes with methods having byte array arguments. There are about 100 methods in total, and the array size ranges from 5-10 to a few 100 bytes. How should I generate and store the test arrays?
I started to create them manually and store them in the test code in hex strings. I worked a lot with such binary strings, so I can read them relatively easily ("I don't even see the code. All I see is blonde, brunette, redhead.") The problem is, this approach is slow, and I think using an automatic generator would result in more maintainable tests. But how should I test that the output of the generator is correct? Sounds like Catch-22...
I would suggest a few approaches, but not sure which one is suitable or even possible for you since there are no examples of the methods you have in your case.
If you could provide an example of your method and explain its working it will be useful. What do your 100 odd methods do?
1)Try refactoring and extracting the logic which works with the byte arrays in the 100 odd methods to a few helper methods. This way the helper methods can deal with the byte arrays and then pass on the de-serialized objects to the 100 odd methods, which will now start using objects for their processing.
OR
2) Personally I prefer to have the byte arrays in the code next to the test methods, the current approach you have taken. Maybe a few combination of inputs as attributes to the functions (use NUnit RowTest extension). This makes the unit tests relatively independent of other tests. If you change parameters then only that particular unit test should be affected.
The biggest issue with a generator is that it could become very complex with logic for returning the byte arrays for each of the 100 odd methods. Changes to the generator could affect all your unit tests.
Unit tests should be easy to maintain and Independent. By introducing a generator you are adding a dependency and increasing the complexity.
Cheers!