[英]How to create Global Variables in a Unit Test using Visual Studio?
I have different TestClasses in different .cs file in my visual studio and I want to share some global variable data which is common for every TestMethod in the TestClass. 我在Visual Studio中的不同.cs文件中有不同的TestClasses,并且我想共享一些全局变量数据,这对于TestClass中的每个TestMethod都是通用的。
I would like to know how can I achive this ? 我想知道如何实现? I am trying to use static or constant variables but where can i declare them when different TestClasses in different .cs files want to use them?
我正在尝试使用静态或常量变量,但是当不同.cs文件中的不同TestClasses要使用它们时,该在哪里声明呢?
When I had the same problem I created a base class for tests which contained all the common data. 当我遇到相同的问题时,我为测试创建了一个基类,其中包含所有通用数据。 This is better from OO point of view.
从面向对象的角度来看,这更好。
But you can also declare a public or internal static class with all you constants and data, this is not very elegant but I don't see technical problems with it. 但是您还可以使用所有常量和数据声明一个公共或内部静态类,这不是很优雅,但我认为它没有技术问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.