编写通用测试 [英] Writing generic tests

查看:78
本文介绍了编写通用测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是Visual Studio的单元测试功能可用/支持的内容,并且对通用测试有疑问。


我有一组测试必须在一系列场景中重复这些场景(场景可以被视为初始化静态类的不同方式,然后针对类运行一组标准测试)。


所以用英语我想要这样做:


  1. 使用"development"进行初始化
  2. 运行标准测试集。
  3. 使用"生产"初始化课程
  4. 运行标准测试集。
  5. 可能还有其他多个场景......


测试集就像20个[TestMethod]方法。


当然我可以为每个场景创建一个测试类一遍又一遍地粘贴在一组测试中但显然这是不可取的。


理想情况下,我要做的是将测试方法放在某个测试类中,并使用相关的scen实例化该类ario然后从我的测试代码调用标准类中的每个测试方法 - 在方案类中的测试方法调用只是一个
单行调用标准测试方法。


但[TestMethod]是否有办法调用其他[TestMethods],以便单元测试系统将这些视为真正的单元测试调用?


换句话说可以[TestMethod]称之为:

 VisualStudio.UnitTesting.ExecuteTest(()=> standardInstance.SomeStandardTest); 

还是什么? (其中SomeStandardTest本身用[TestMethod]修饰)。


Thx







$

解决方案

< blockquote>

Hi Korporal,

感谢您在MSDN论坛发帖。


根据您的描述,您有不同的测试场景,如UAT test \ PROD因此,您想要通过属性定义来选择可以执行哪些测试方案,我是对的吗?


如果是这样,您可以覆盖中的特定预定义目标配置文件
" DependsOn"性能即可。然后根据代码中的不同环境进行不同的调用。


参考:


https://msdn.microsoft.com/en-us/library/ms366724.aspx?f=255&MSPPError=-2147217396


希望有所帮助。


 


祝你好运,


弗莱彻


I'm no guru on what's available/supported by the unit test capabilities of Visual Studio, and have a question about generic tests.

I have a set of tests that must be repeated for a host of scenarios (the scenarios can be considered as different ways of initializing a static class then running a set of standard tests against the class).

So in English I want to do this:

  1. Init the class with "development"
  2. Run the set of standard tests.
  3. Init the class with "production"
  4. Run the set of standard tests.
  5. Probably multiple other scenarios too...

The set of tests is like 20 [TestMethod] methods.

Of course I can create a test class for each scenario and paste in the set of tests over and over but clearly this is undesirable.

Ideally what I'd do is put the test methods in some test class and instantiate that class with the relevant scenario and then from my test code invoke each test method in the standard class - the tests methods calls in the scenario class would just be a one-liner invoking the standard test method.

But is there a way for [TestMethod] to invoke other [TestMethods] so the the unit test system considers these as real unit test calls?

In other words can a [TestMethod] call something like:

VisualStudio.UnitTesting.ExecuteTest(() => standardInstance.SomeStandardTest);

or something? (where SomeStandardTest is itself decorated with [TestMethod]).

Thx

解决方案

Hi Korporal,
Thank you posting in MSDN forum.

According your description, you have different test scenarios, like UAT test\PROD test etc. So, you want to choose which test scenarios could be perform via defined by attribute, am I right?

If so, you could override specific predefined targets in config file or "DependsOn" properties. Then do different calls according different environment in your code.

Reference:

https://msdn.microsoft.com/en-us/library/ms366724.aspx?f=255&MSPPError=-2147217396

Hope it helps.

 

Best regards,

Fletcher


这篇关于编写通用测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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