C# + NUnit: Unit testing methods with byte array arguments -
i write unit tests classes methods having byte array arguments. there 100 methods in total, , array size ranges 5-10 few 100 bytes. how should generate , store test arrays?
- should generate them manually or generator code (which should unit tested, too)?
- should generate them in memory during test, or should generate them in advance , store them somewhere?
- in latter case, should store them in files (even if unit tests shouldn't touch file system), or should store them inside test code (for example, in strings in hexadecimal format, this: "47 08 00 14 etc.")?
i started create them manually , store them in test code in hex strings. worked lot such binary strings, can read them relatively ("i don't see code. see blonde, brunette, redhead.") problem is, approach slow, , think using automatic generator result in more maintainable tests. how should test output of generator correct? sounds catch-22...
i suggest few approaches, not sure 1 suitable or possible since there no examples of methods have in case.
if provide example of method , explain working useful. 100 odd methods do?
1)try refactoring , extracting logic works byte arrays in 100 odd methods few helper methods. way helper methods can deal byte arrays , pass on de-serialized objects 100 odd methods, start using objects processing.
or
2) prefer have byte arrays in code next test methods, current approach have taken. maybe few combination of inputs attributes functions (use nunit rowtest extension). makes unit tests relatively independent of other tests. if change parameters particular unit test should affected.
the biggest issue generator become complex logic returning byte arrays each of 100 odd methods. changes generator affect unit tests.
unit tests should easy maintain , independent. introducing generator adding dependency , increasing complexity.
cheers!
Comments
Post a Comment