简体   繁体   English

存储静态单元测试变量的最佳方法是什么?

[英]What is the best way to store static unit test variables?

I am currently using NUnit and testing a class library. 我目前正在使用NUnit并测试类库。 Up until now, I have used a list of constants at the top of the test class to hold some static test variables. 到目前为止,我已经在测试类的顶部使用了常量列表来保存一些静态测试变量。 Is this the best way to do this, or is there a more fluent way to handle it? 这是最好的方法吗,还是有更流畅的方式来处理它?

By "static test variables" do you actually mean constants (whether genuine constant, immutable instances or just ones you don't change)? 通过“静态测试变量”,你实际上是指常量(是真正的常量,不可变实例还是只是你不改变的实例)? I use those frequently, and just put them at the top of the test class. 我经常使用它们,只是将它们放在测试类的顶部。

If there are several related test classes, it can be handy to separate out common values into a different class though. 如果有几个相关的测试类,那么将常用值分成不同的类可能很方便。 (It could act as your base class, but I'm not terribly fond of using inheritance just to get access to things more easily. Java static imports are handy there...) (它可以作为你的基类,但我不是非常喜欢使用继承只是为了更容易访问事物.Java静态导入在那里很方便......)

每当我可以,我将数据外部存储在我们检查到源代码管理的xml文件中。

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

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