Roslyn - dynamic (runtime) flow

别说谁变了你拦得住时间么 提交于 2019-12-12 04:05:41

问题


I started playing with Roslyn. It’s relatively easy to parse code and do static analysis.

I wonder if it’s possible to use it for runtime analysis? I want to call a method with parameters and check which branches were executed. In other words, I need a runtime execution plan. Is it something which could be done with Roslyn?


回答1:


I don't know what the best solution is and I would defer to anything SLaks recommends in most cases.

However...

If you want to do this with Roslyn you certainly can. In fact at my company does something similar (we map unit tests to the methods they invoke).

Here's a high level overview of our approach.

  1. Rewrite every single function in the solution to log when it is hit in some global static lookup/data-structure. You can iterate over every file one at a time and use the CSharpSyntaxRewriter on each one. (In your case you'll be rewriting on a branch or line-by-line basis)

  2. Run each unit test one at a time and see what gets run by analzying your global lookup.

  3. Aggregate the results across all your unit tests to understand your complete code coverage.



来源:https://stackoverflow.com/questions/30958406/roslyn-dynamic-runtime-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!