c# - Unit test class with one public and multiple private methods -


i'm having little trouble understanding how approach following in order unit test class.

the object under test object consists out of 1 public method, 1 accepts list of objects of type , returns object b (which binary stream). due nature of resulting binary stream, gets large, not nice comparison test output. stream built using several private instance helper methods.

class foo {     private binarystream mbinarystream;     public foo() {}     public binarystream bar(list<object> objects) {         // perform magic build , return binary stream;         // using several private instance helper methods.         magic(objects);         moremagic(objects);     }     private void magic(list<object> objects) { /* work on mbinarystream */ }     private void moremagic(list<object> objects) { /* work on mbinarystream */ } }; 

now know need test behaviour of class, bar method. however, it's undoable (both space , time wise) compare output of method predefined result. number of variations large (and corner cases).

one option go refactor these private helper methods (a) separate class(es) can unit tested. binary stream can chopped smaller better testable chunks, here goes lot of cases need handled , comparing binary result defy quick time of unit test. option i'd rather not go for.

another option create interface defines these private methods in order verify (using mocking) if these methods called or not. means these methods must have public visibility, not nice. , verifying method invocations might enough test for.

yet option inherit class (making privates protected) , try test way.

i have read of topics around such issue, seem handle testable results. different challenge.

how unit test such class?

well on top of how deal private methods. testing stream correct output. i'd use limited set of input data, , exercise code in unit test.

all potential scenarios i'd treat integration test.

so have file (say xml) input , expected output. run through it, call method input , compare actual output expected, report differences. part of checkin, or before deploy uat or such.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -