[英]How to write automated tests - Test case as a function or test case as a class
I am having a design problem in test automation:- 我在测试自动化中遇到设计问题:-
Requirements - Need to test different servers (using unix console and not GUI) through automation framework. 要求-需要通过自动化框架测试不同的服务器(使用UNIX控制台而不是GUI)。 Tests which I'm going to run - Unit, System, Integration
我要运行的测试-单元,系统,集成
Question: While designing a test case, I am thinking that a Test Case should be a part of a test suite (test suite is a class), just as we have in Python's pyunit framework. 问:在设计测试用例时,我认为测试用例应该成为测试套件的一部分(测试套件是一个类),就像在Python的pyunit框架中一样。 But, should we keep test cases as functions for a scalable automation framework or should be keep test cases as separate classes(each having their own setup, run and teardown methods) ?
但是,我们应该将测试用例保留为可扩展的自动化框架的功能还是应该将测试用例保留为单独的类(每个类都有各自的设置,运行和拆卸方法)? From automation perspective, Is the idea of having a test case as a class more scalable, maintainable or as a function?
从自动化的角度来看,将测试用例作为一类的想法是否更具可扩展性,可维护性或功能性?
Normally Test Cases are used as classes rather than functions because each test case has own setup data and initialization mechanism. 通常,将测试用例用作类而不是函数,因为每个测试用例都有自己的设置数据和初始化机制。 Implementing test cases as a single function will not only make difficult to set up test data before running any test case, but yes you can have different test method in a test case class if you are running same test scenario.
将测试用例实现为单个功能不仅会使得在运行任何测试用例之前难以设置测试数据,而且是的,如果您运行的是相同的测试场景,则可以在测试用例类中使用不同的测试方法。
The following is my opinion: 以下是我的意见:
Pros of writing tests as functions: 将测试编写为函数的优点:
Cons of writing tests as functions: 将测试编写为函数的缺点:
Not maintainable - Because if there are huge number of tests where same kind of pre-requisites are required, the test case author has to maintain calling each pre-requisite function in the test case. 不可维护-因为如果存在大量需要相同先决条件的测试,则测试用例作者必须维护调用测试用例中的每个必备功能。 Same for each teardown inside the test case
测试用例中的每个拆解都相同
If there are so many calls to such a pre-requisite function inside many test cases, and if anything changes in the product functionality etc, you have to manually make efforts in many places again. 如果在许多测试用例中有如此多的对此类必备功能的调用,并且产品功能等发生任何变化,则您必须在许多地方再次手动进行工作。
Pros of writing test cases as classes: 将测试用例编写为类的优点:
Cons of writing test case as classes: 将测试用例编写为类的缺点:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.