How come there's no C# equivalent of python's doctest feature?

冷暖自知 提交于 2019-12-22 06:39:06

问题


Seems like it would be a good way to introduce some people to unit testing.


回答1:


Well for one thing, the documentation for doctest talks about "interactive Python sessions". There's no equivalent of that in C#... so how would the output be represented? How would you perform all the necessary setup?

I dare say such a thing would be possible, but personally I think that at least for C#, it's clearer to have unit tests as unit tests, where you have all the benefits of the fact that you're writing code rather than comments. The code can be checked for syntactic correctness at compile-time, you have IntelliSense, syntax highlighting, debugger support etc.

If you're writing code, why not represent that as code? Admittedly it's reasonably common to include sample code in XML documentation, but that's rarely in the form of tests - and without an equivalent of an "interactive session" it would require an artificial construct to represent the output in a testable form.

I'm not saying this is a bad feature in Python - just that it's one which I don't believe maps over to C# particularly well. Languages have their own styles, and not every feature in language X will make sense in language Y.




回答2:


Microsoft Roslyn is coming. I believe this could be an enabling technology for doctest.net

..and GWT.net also.

:)



来源:https://stackoverflow.com/questions/3965547/how-come-theres-no-c-sharp-equivalent-of-pythons-doctest-feature

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