简体   繁体   English

在ac#Visual 2010网站中对支持类进行单元测试

[英]Unit testing a support class within a c# Visual 2010 website

I would like to start unit testing support classes that are within a website project. 我想开始一个网站项目中的单元测试支持类。 In a perfect world the website's support classes would have been placed inside a seperate assembly thus making unit testing very straight forward. 理想情况下,网站的支持课程将放置在单独的组件中,从而使单元测试变得非常简单。 What would be the best pattern to automate unit testing of support classes. 什么是使支持类的单元测试自动化的最佳模式。

Your unit tests don't have to link to an assembly. 您的单元测试不必链接到部件。 They can link and build the CS files directly. 他们可以直接链接并构建CS文件。

Right click your project, select the Add -> Existing Item option. 右键单击您的项目,选择添加->现有项目选项。 Browse to the code, and select what you want to add. 浏览到代码,然后选择要添加的内容。 Instead of clicking the "Add" button, which would copy the files, click the little arrow on the side of the "Add" button, and select "Add As Link" from the drop-down menu. 与其单击将复制文件的“添加”按钮,还没有单击“添加”按钮侧面的小箭头,然后从下拉菜单中选择“添加为链接”。

Using this approach, you can link directly to the code in your test project, without needing a compiled assembly. 使用这种方法,您可以直接链接到测试项目中的代码,而无需编译的程序集。 Also, whenever the code changes, your unit test project will be updated automatically. 另外,只要代码更改,您的单元测试项目就会自动更新。

If you have loads of money and time then testing with the shot gun approach makes sense. 如果您有很多金钱和时间,那么使用shot弹枪方法进行测试就很有意义。 Infact test until you are blue in the face. 进行实况测试,直到脸色发青。 The thing to consider is the 80/20 rule its only about 20% of your tests that are going to give you 80% of your value. 要考虑的是80/20规则,只有大约20%的测试可以为您带来80%的价值。

Try to focus on the critical path and then based on that all code that is referenced will be automatically tested. 尝试着眼于关键路径,然后根据所引用的所有代码将自动进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM