C# 语言转换测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-01 08:58:39  来源:igfitidea点击:

Language Conversion Testing

提问by jfs

We created a tool which converts a language called P2, a language similar to assembly which I think exists only in Japan, to C#. There are at least a hundred modules written in P2 and we want to verify if the conversion to C# is right? How can we test this?

我们创建了一个工具,可以将一种名为 P2 的语言(一种类似于我认为仅存在于日本的汇编语言)转换为 C#。至少有一百个模块是用 P2 编写的,我们想验证转换为 C# 是否正确?我们如何测试这个?

回答by Jon Limjap

You don't test the converter, you test the final code.

您不测试转换器,而是测试最终代码。

If the code doesn't compile, clearly your converter is failing. If the code compiles and your functionality tests fail, then you can tweak the code so that it passes the test. If you are fairly successful you should see that you only need to fix the modules that actually fail.

如果代码不能编译,很明显你的转换器失败了。如果代码编译并且您的功能测试失败,那么您可以调整代码以使其通过测试。如果您相当成功,您应该看到您只需要修复实际失败的模块。

Goodluck!

祝你好运!

回答by Marcus Downing

Short of a formal mathematical proof (which I imagine would be difficult), the proof of the pudding is in the unit tests. You have to find a way to wrap the converted C# snippets, compile the and run them under a similar environment, then compare the output against the original. Unless you're rigorous in your testing, there's no way you can be confident of the result.

缺少正式的数学证明(我认为这很困难),布丁的证明是在单元测试中。您必须找到一种方法来包装转换后的 C# 片段,在类似环境下编译并运行它们,然后将输出与原始输出进行比较。除非您的测试非常严格,否则您无法对结果充满信心。