有关使用 NUnit 测试整个功能的书籍或文章
是否有任何书籍或文章向您展示如何使用 NUnit 来测试程序的全部功能?这种类型的测试有名称吗?
这与 NUnit 进行单元测试的典型用途不同,在单元测试中测试单个类。这与验收测试类似,不同之处在于它是由开发人员编写的,用于辨别程序是否执行了他们解释为客户希望程序执行的操作。我不需要它被非程序员可读或为非程序员生成可读的规范。
我遇到的问题是保持此功能测试代码的可维护性。我需要帮助来组织我的功能测试代码。我还需要帮助组织程序代码以便以这种方式驱动。我很难在仍然拥有良好的代码设计的同时向程序发出命令。
目前,我有一个名为 Program 的类,其中有一个名为 Run 的公共方法。每次测试时,我都会像用户一样从程序的开头开始,然后到达程序中可用特定功能的所需点。然后我以某种方式使用该功能并验证它是否达到了我的要求。我有一个名为 Commands 的类,它将程序的不同功能公开为方法。 Commands 对象的实例被传递给程序,并最终传递给每个 Form 类。这些将订阅 Commands 类中由命令类的方法调用的事件(每个方法一个匹配事件)。通过指向使用用户界面的特定部分时调用的方法来订阅事件,从而允许我的测试驱动整个程序。如果针对当前未订阅的事件调用 Command 对象上的方法,则会引发 FeatureMissingException。
所有这些都有效,但我不喜欢 Command 类。它变得太大,职责太多(程序的每个功能)。 Commands 类也是一个依赖磁铁(所有 Form 类都有它的实例,但仅订阅代表可通过其 UI 激活的功能的事件)。
Are there any books or articles that show you how to use NUnit to test entire features of a program? Is there a name for this type of testing?
This is different from the typical use of NUnit for unit testing where you test individual classes. This is similar to acceptance testing except that it is written by the developer to discern that the program does what they interpreted as being what the customer wants the program to do. I don't need it to be readable by non-programmers or to produce a readable specification for non-programmers.
The problem I am having is keeping this feature testing code maintainable. I need help in organizing my feature testing code. I also need help organizing the program code to be drivable in this way. I am having a hard time being able to issue commands to the program while still having good code design.
Currently I have a class called Program with a single public method called Run. With every test I start at the beginning of the program like the user would and then get to the desired point in the program where a particular feature would be available. I then use that feature in some way and verify it did what I want. I have a class called Commands that exposes different features of the program as methods. An instance of the Commands object is passed to the program and it eventually gets passed to every Form class. These will subscribe to events from the Commands class that are called by the methods of the command class(one matching event per method). The events are subscribed to by pointed to the method that is called when a certain part of the user interface is used, thus allowing the entire program to be drivable by my tests. If you call a method on the Command object for an event that is currently not subscribed to, a FeatureMissingException is thrown.
All of this works but I don't like the Command class. It is getting too large with too many responsibilities (every feature of the program). The Commands class is also a dependency magnet (all the Form classes have an instance of it but only subscribe to the events that represent features that can be activated through their UI).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它称为集成测试。集成测试自动化起来要困难得多,而且通常是手工完成的。不过,许多更简单的测试仍然可以使用 NUnit 完成 - 您不必做任何特殊的事情,只需不要使用 Mock(就像您应该为单元测试所做的那样),这样您就可以测试模块如何实际组合在一起。
上下文/规范< /a> 是组织这些测试的好方法。
It's called integration testing. Integration tests are much more difficult to make automated, and are very often done by hand. Many simpler tests can still be done using NUnit though - you don't have to do anything special, just don't use Mocks (like you should be doing for unit tests) so you can test how the modules actually fit together.
Context/specification is a good way of organizing these tests.
您想要做的是 集成测试,就像其他答案所建议的那样。这将允许您进行功能/特性测试。最常见的框架为 StoryQ 或 SpecFlow.这允许您以 BDD 风格开发测试,并且大部分可以根据规范自动化你想要的。
像 Selenium 这样的工具允许您在浏览器中进行功能测试,以完成最终用户会做的事情。所有这些都可以用 NUnit 驱动,因为 NUnit 纯粹是一个用于运行测试的框架,无论是单元测试还是大型功能测试
What you want to do is integration testing, like the other answer suggests. This will allows you to functional/feature testing. The most common framework for this for StoryQ or SpecFlow. This allows you to develop your tests in a BDD style and can be mostly be automated against the spec that you want.
Tools like Selenium allow you to do functional testing in a browser to do what the end user would do. All of these can be driven with NUnit since NUnit is purely a framework for running tests be them Unit tests to large functional tests