Watin C# 类变得非常大,分解它们的最佳方法是什么
在测试网站时,我最终得到了非常长的类文件,测试了网站的许多不同部分。我可以将它们分成单独的类,但随后我需要传递浏览器对象,这似乎会产生很多额外的开销。我还可以添加一个“代码文件”,我认为它可以包含在我正在使用的主类中并让它保存函数。将大的 C# 类文件分解为较小的文件的正确方法是什么?
In testing a site, I end up getting really long class files testing lots of different parts of a website. I could break them into separate classes but then I would need to pass around Browser Objects and seems like lots of extra overhead. I could also add a "code file" which I think could just be included in the main class I'm working in and have it hold functions. Whats the right way to break up a big c# class file into smaller files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会将它们分成按类似功能分组的文件,并使用 部分关键字。
另外 -
如果你的班级变得那么大,我怀疑你给它承担了太多的责任。
I would break them into files grouped by similar functionality, and use the partial keyword.
Also -
If your class is getting that big, I suspect that you are loading it up with too many responsibilities.
正如您所说,您的课程“测试网站的许多不同部分”为网站的单个部分创建一个课程。
例如,您可以采取两个步骤进行重构。
1.使用partial关键字将类分成多个文件。
2. 逐步删除部分类并根据其职责重命名类名。
As you said your class "testing lots of different parts of a website" make a single class for single part of a website.
For instance you can take two steps for refactoring.
1. Break class into several files using partial keyword.
2. Step by step remove partial and rename class name accroding to its responsobility.
它将它分为不同的类。
类应该有单一目的,方法应该执行单一操作,好的代码应该能够自我解释。
Its to seperate it into seperate classes.
A class should have a single purpose, a method should do a single action, good code should explain itself.
我们的项目中有超过 250 个测试。我们最初使用部分类,但发现找到一个特定的测试来运行很痛苦,因此我们将类结构化如下: -
然后,在 VS 的测试视图窗口中按测试名称对它们进行分组,这将向您显示...
We have over 250 tests in our project. We initially used partial classes but found finding a specific test to run a pain, so we've structured the classes like this: -
Then, in your Test View window in VS group them by Test Name which will show you...