java - Make member public to unit-test it -


i know there many question concerning unit-tests of private members within classes. of them come conclusion having private members need tested design-flaw needs refactoring (e.g. see here). still have 1 last question:

when refactor private members new classes become (public) api-members intended avoid. simplifying our client class polute our api designing new publicly visibly helper-class. of course 1 might write test-code within assembly , make helpers internal we´d ship test-code production-site.

i assume there no right answer issue perhaps have great ideas avoid situations?

regarding c# there 1 last trick try

  1. make class/members internal
  2. in assembly test, open assemblyinfo.cs file , make internals visible test-project/assembly adding following attribute:

[internalsvisibleto("yourtestproject")]

this makes members invisible outside assembly, except sake of test within "yourtestproject"-assembly.

more info on attribute can found on msdn.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -