Running unit tests on nested functions

后端 未结 6 2050
野的像风
野的像风 2020-12-16 17:32

I come from the Java world, where you can hide variables and functions and then run unit tests against them using reflection. I have used nested functions to hide implement

6条回答
  •  甜味超标
    2020-12-16 18:10

    No way to get inner function from outer function object (see the other replies!). Yet both unit tests and closures have made (for me at least) amazing developer performance improvements. Can we have both? Can we test nested functions in isolation?

    Not easily.

    However, such could seemingly be achieved with use of python modules parser, ast, or tokenizer to dice up the code itself, extracting inner functions (by some path through the nesting), and allowing tests to run them with state from enclosing functions (values for closed-over names) and stubs/mocks for more-nested functions (defined within the test target).

    Anybody know of anything like this? Googling failed to find anything.

提交回复
热议问题