940526 - 我可以在设计时测试C#表单吗? [英] 940526 - Can I test a C# form while designing?

查看:69
本文介绍了940526 - 我可以在设计时测试C#表单吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,当创建包含表单的Windows应用程序时,在运行应用程序之前有一个热键可以测试它(Ctrl + T)。

C#表单有这样的东西吗? div class =h2_lin>解决方案

您可以使用单元测试文件中的不同快捷方式运行单元测试,有关详细信息,请参阅此链接 https://msdn.microsoft.com/en-us/library/ms182470.aspx [ ^ ]



所以如果你运动你可以在单元测试中使用你的表单

你的设计表面只会执行构造函数,所以如果你想要翻转你的设计师,你必须做你想在构造函数中测试的东西,这是虽然没有广泛用于我的知识。




以下文章将帮助您在Visual S中设置单元测试项目tudio。

为c#创建单元测试代码 [ ^ ]



创建测试后,可以使用Ctrl + R运行它们,A



当首先编写测试然后编写方法以适应它们时,这些单元测试也用于TDD。

更多关于TTD的信息:

.NET TDD(测试驱动开发)示例 - 第1部分 [ ^ ]







运行测试会导致代码无论如何编译所以你不需要构建ev ents:

但是就像FYI一样,您可以在Build Events下的项目属性窗口中设置预编译/后编译命令。你可以在这里使用高级bat脚本,但我发现最好只调用.bat文件。

这里有更多内容:

打开项目属性 [ ^ ]

构建事件选项卡 [ ^ ]

构建事件关键词 [ ^ ]



希望这会有所帮助^ _ ^

Andy


In C++, when creating a Windows application which includes a form, there's a hotkey to test it before running the application (Ctrl+T).
Is there such a thing for C# forms?

解决方案

You can run your unit test using a different shortcuts in your unit test file, see this link for details https://msdn.microsoft.com/en-us/library/ms182470.aspx[^]

So if you exercise your form in unit tests you can
Your design surface will only execute the constructor, so if you wanna flip to and from your designer you'll have to do what you wanna test in the constructor, this is not widely used for that to my knowlege though.


Hi,
The following article will help you set up a unit test project within Visual Studio.
Creating Unit tests for your c# code[^]

Once you have your tests created then you can run them with Ctrl+R,A

These unit tests are also used in TDD when the tests are written first then the methods are written to accommodate them.
More on TTD here:
.NET TDD (Test Driven Development) by example - Part 1[^]



Running the tests will cause your code to compile anyway so you don't need build events:
But just as an FYI, you can set up pre-compile / post-compile commands in the project properties window under the Build Events. You can have advanced bat script here but I find it's best to just call a .bat file.
More on this here:
Open project properties[^]
Build Events tab[^]
Build Events key words[^]

Hope this helps ^_^
Andy


这篇关于940526 - 我可以在设计时测试C#表单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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