为什么没有C#相当于Python的文档测试功能? [英] How come there's no C# equivalent of python's doctest feature?

查看:163
本文介绍了为什么没有C#相当于Python的文档测试功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像它会推出一些人的单元测试的好方法。

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

推荐答案

好了一件事,在文档,文档测试谈交互式Python会话。有没有在C#中没有对应的是......因此如何将输出重新presented?你将如何进行所有必要的设置?

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?

我敢说这样的事情是可能的,但我个人认为,至少在C#中,它更清晰有单元测试的作为单元测试的,那就是你有一个事实,即所有好处你写code,而不是评论。在code可以在编译时检查语法的正确性,你有智能感知,语法高亮,调试器支持等。

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.

如果你正在写code,为什么不重新present说的为code 的?诚然,这是相当常见的,包括样品code在XML文档中,但这是很少在测试的形式 - 并没有互动式会议的等效这将需要一个人造结构来重新present输出的测试的形式。

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.

我并不是说这是一个Python坏的功能 - 只是它的其中一个,我不相信在映射到C#特别好。语言有自己的风格,并在语言X不是每一个功能将是有意义的语言Y

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.

这篇关于为什么没有C#相当于Python的文档测试功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆