楼主: crazypeter2005

[原创] 做一个开发人员认可的测试人员(系列3)-也谈自动化测试框架[缓慢更新中]

[复制链接]
论坛徽章:
64
罗罗诺亚·索隆
日期:2017-09-07 16:40:52itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03祖国65周年纪念徽章
日期:2014-09-28 15:11:01青年奥林匹克运动会-五人制曲棍球
日期:2014-09-12 15:36:032014系统架构师大会纪念章
日期:2014-08-04 09:33:532013系统架构师大会纪念章
日期:2014-08-04 09:33:53
11#
 楼主| 发表于 2013-8-6 09:17 | 只看该作者
本帖最后由 crazypeter2005 于 2013-8-6 15:15 编辑

框架啥的其实都只是辅助的,简单的xUnit用好了,也是有很强大的功效。
只要配合Developer做好关键路径(各种商业路径),设置好需要验证的关键验证点,测试人员也能把测试给自动化下来的。


使用道具 举报

回复
论坛徽章:
64
罗罗诺亚·索隆
日期:2017-09-07 16:40:52itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03祖国65周年纪念徽章
日期:2014-09-28 15:11:01青年奥林匹克运动会-五人制曲棍球
日期:2014-09-12 15:36:032014系统架构师大会纪念章
日期:2014-08-04 09:33:532013系统架构师大会纪念章
日期:2014-08-04 09:33:53
12#
 楼主| 发表于 2013-8-6 09:20 | 只看该作者
今天转载的第二篇是个棒子写的 什么是好的自动化,其中有些观点我也认同。
2 http://wowlsdl.blogspot.com/2012 ... tion-framework.html
A good test automation framework
Today, I like to mention a little about test automation frameworks.

If you're looking at any kind of job posting (company career site, monster.com, and etc) for a software test engineer now, you will see almost all the posting mention some level of experiences in test automation framework as a requirement. And actually I do use test framework for my testing and it is very useful tool that resolves several limitations of manual testing.

So I thought it is worthwhile to put my thought about what a good test automation framework is in my blog. First, let me scope the area of discussion since test automation framework is a pretty big topic. I'm going to set aside the discussion around pros and cons of test automation in software testing since that's not my main point of this article. And I'm talking about your work related test automation framework not the generic programming language specific test framework. For example, my test automation framework is built on top of JUnit or TestNG. JUnit and TestNG are also test automation frameworks, but those frameworks do not have the specific business logic of my testing.

OK. Let's start. What is test automation frameworks?  Wikipedia mentions "A test automation framework is a set of assumptions, concepts and tools that provide support for automated software testing." My simple definition is "a test automation framework is a program that helps testers execute and validate test cases(test scenarios). So it is a program that helps software testing. The meaning of "help" will be saving time, being more efficient in testing process, gathering useful data easily after test execution and etc compared to the manual human test execution. But it is a program, which means someone has to design, implement and maintain. This brings a very important ground rule of test automation. Benefit of using test automation should always be greater than the effort of designing, implementing and maintaining the test automation. Otherwise there is no point using test automation beside you being cool.

I believe having a good test automation framework is to maximize the benefits of test automation and minimize the effort of implementing and maintaining it. So let me address the characteristics of a good test automation framework.
Have a clear strategy and everyone should be on the same page. This is the most important and most effective way to maximize the benefit of using the test automation framework. There are many different ways to design and implement test automation frameworks. And it is REALLY hard to come up with one solution that will satisfy every test engineers, which means when a test architect or experienced SDET come up with a framework, he/she should explain the strategy of the test automation and help everyone in the team understand how it works and how to use it. Once everyone is on the same page (know how it works and how to use), implementing test cases (scenarios) is much faster and maintaining the framework is much easier. By following a certain rule or instruction, test writers are less distracted and he/she can understand others code very easily. And when it comes to a situation where the current approach does not fit, it is much easier to notice and notify test automation designer (architect or SDET) to resolve the issue with proper solution.
Favor object composition over class hierarchy. This is one advice from Gang of four design pattern. One of the common mistake with test framework is that some framework base class provide too many functionality and become giant class (a few thousand lines of code). This approach works fine at the beginning but it does not scale very well and becomes very complex code base as number of tests grows to handle various test conditions, error scenarios and exceptional cases. One key characteristics of good test framework is to provide flexibility to test writers. Test writers should be able to choose classes or modules they need to execute one test case. Just Mix and Match for their tests.
Separation between test execution and validation. This is more about validation code being independent from test execution. It also means validation code by itself does not contain any context about test cases. What this allows to the framework is that you can package one logical chunk of  validation into one class. It will takes some parameters as source of validation. You call validate() method and it will simply return true or false. No decision making process here. For example, if error expecting flag is set do this. if some other case do that. NO. JUST DO THE VALIDATION. What does this allow test writers? You gather source of validation during test execution and pick and construct validation instances you need from pool of validation classes. DO NOT let the validation code to be workflow. LET IT BE collection of appropriate validations for each test case. This promotes great re-usability of the code and less complex code.
Build the test framework to support the way test execution steps are defined. The ideal framework, in my opinion, is that defined (written or thought) test execution steps are transformed to test automation code with 1:1 mapping. This seems pretty easy to do but this requires thoughtful design to expose natural language like method names and encapsulate well structured implementation details. One way to think about this is that you're providing framework for test writers who are not as technical as you. This promotes great readability of the code as well.
Be cautious about re-factoring codes. Re-factoring is useful work. It's a good process that turns spaghetti codes to well-structured code. But often times, test automation writers get confused by this concept where he/she does not understand the difference between test automation code and development code. If you look closely on test automation code, there are two big parts: one is test execution steps related part and the other is test automation framework part that supports test execution step code. Re-factoring should largely applied in the latter part of automation code. Here is the common problem that I've seen. At first, test cases that a tester is implementing is very similar beside some inputs, config, or environment, so he re-factor the common piece in one method. Looks good. On the next iteration or release, he adds more test cases. He notices a little variation of the execution step or input, so he add some conditionals (if/switch statement) to the common method. As more iteration or releases come by, the common method becomes more and more complex. Complexity is not the only problem. His thought process of executing test steps is restricted by existing code base and he is trying to fit his thought on that code path. Also it is very hard for other testers to read and follow the logic. Refactoring test execution steps code can be very dangerous because it restricts testers thought process, makes test automation code less flexible, and makes readability of the code very bad and it hurts other test writers to take over. I admit that it is hard process because sometime it is hard to draw a line between test step code and supporting code. The key is to have test execution steps to be flexible and to have supporting code to be well structured.
Pinpointing the failure is more important than handling error gracefully. Do not be scared of null pointer exception. Automation code is not production code. I don't think this needs a lot of explanations
Minimize bootstrap code. Setup methods like @BeforeClass in JUnit or some sort of prep code runs before the test run is useful. But it also prevent your framework from being flexible. And it also make the framework very heavy. Sometimes you just want to check a simple validation that was used in test automation for other purpose. Well modularized code does not need much bootstrap code. You should be able to run your test in main method if your automation framework is well modularized.

使用道具 举报

回复
论坛徽章:
64
罗罗诺亚·索隆
日期:2017-09-07 16:40:52itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03祖国65周年纪念徽章
日期:2014-09-28 15:11:01青年奥林匹克运动会-五人制曲棍球
日期:2014-09-12 15:36:032014系统架构师大会纪念章
日期:2014-08-04 09:33:532013系统架构师大会纪念章
日期:2014-08-04 09:33:53
13#
 楼主| 发表于 2013-8-6 09:20 | 只看该作者
I previously wrote about test automation framework with details related to coding. (I would call it part 1)

Today, I like to mention a little bit more technical explanations of a good test automation framework.

I guess you (test engineers) have worked on test automation framework that was written by someone else and also worked on designing it from scratch. Have you feel some fuzzy or itchy feeling about the test automation you're working on? Something seems to be wrong but hard to explain? Does it take hours just to add a new test case? Do you feel test execution is heavy? I have the same feeling as well. I've been seriously thinking about that and I came up with following technical details. I don't think it is just because of  different coding style nor different thinking process. Hopefully, this blog actually scratch those itchy feelings.

1. Goal setting: This is about initial design of test automation framework. You need to set two goals. If you can satisfy both goals from framework user (testers average 2-3 years on automation), I would say your design is successful. The first goal is the framework should be easy to understand, easy to use and easy to implement. And the second goal is you need to design test framework in a way that volume of the code increases but complexity of the code does not. This seems to general and yes it depends on the context of your application. But if you write test automation framework from scratch, please do not simply start with drawing diagrams. Think about consumer of your framework. And also how the framework will grow and not become collection of giant and complex code base.

2. Do not re-factor test execution step code. This is for the user of test framework. I mentioned from my first blog to be cautious about it. Now I change my mind. Again, Do not re-factor test executions step code.  It really has many side effects.

First, your coding is restricted by re-factored code. You framework API provide several functionality and normally those are the components that supports your test execution steps. Your test execution code should be just mix and match of those components. Once you re-factor the execution steps, you are losing your flexibility of test case implementation. It's really silly to be proud of test execution step code  to be one function and it takes 6-7 parameters. Also, you lose the readability of test execution steps. Now how can you replace your test case document with your code? It's so hard to read. DRY (Do not Repeat Yourself) does not applied to test execution step code.

Second, you are adding unnecessary complexity by re-factoring code. I have a good metaphor to back up this argument. Let's say you want to test a car and you have test system that control every part of the car. But that system provides only one button for control. With one button click you need to come up with a way to start the engine, step on gas, break, changing gear, steering wheel control, lights, radio and etc. How would you control that with one button. Yes, you need to come up with some sort of Morse Code to differentiate the operations. "bip bip wait wait bippppp bip wait bippppp" that means turn the head light on. How about you have buttons for each operations. Engine button, break button, accelerator button, light button, changing gear button and etc.

Third, you don't gain much anyways. In test automation framework, what part of the codes are most frequently and most likely added and modified? It is test executions step code. Test cases are keep added and modified as the application grows sprint by sprint. Let's say you have 8 distinct test case which exercise different aspects of the application. Let's say test case 1 and 2 have 70% of the same code. And test case 2 and 3 share 60% of code a slight different way. Test case 3 and 4 shares 65% of code but also slightly different way and so on. It looks like a lot of codes are repeating. Now you start re-factoring. I can tell you; it not easy. What do you end up having? Excessive object composition or excessive class hierarchy of code. Or. you can see the same name of re-factored code with less parameters all over the place. Base class or helpers. Now look at your code after re-factoring. Lines of code you save is not much. And guess what new test case comes in and you need to re-re-factor your code.

Forth, it's not uniformly re-factored and not re-factored by responsibility or business logic. Most of test execution step code re-factoring happens due to repeating code. Not like automation framework code. Framework code is re-factored to achieve Open-Close principle or component decomposition. And it is normally uniformly re-factored because it has its own purpose. Refactoring is not simply putting repeating code in one place. Refactoring makes the code more maintainable and extensible. Existing test execution step changes in several different way, I tell you I've experienced..... It's hell.

Fifth, putting repeating code to base class causes weak cohesion and giant class (3000 lines of code kind of giant class). I'll explain this more in details later. I personally do not recommend people to use TestBase class because once you open the door, it's open for any code to go in. It stars with really essential pieces of code for bootstrap. And later add some more helpers. And later people start putting repeating test execution step code. And people start to add another base class that inherit from TestBse class. Adding if statements and switch statements. Where is the cohesion? What does this base class specifically do? Everything!


A good test automation framework continues....

使用道具 举报

回复
论坛徽章:
64
罗罗诺亚·索隆
日期:2017-09-07 16:40:52itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03祖国65周年纪念徽章
日期:2014-09-28 15:11:01青年奥林匹克运动会-五人制曲棍球
日期:2014-09-12 15:36:032014系统架构师大会纪念章
日期:2014-08-04 09:33:532013系统架构师大会纪念章
日期:2014-08-04 09:33:53
14#
 楼主| 发表于 2013-8-6 09:26 | 只看该作者
今天给希望做自动化测试的人推荐2本书:

使用道具 举报

回复
论坛徽章:
64
罗罗诺亚·索隆
日期:2017-09-07 16:40:52itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03祖国65周年纪念徽章
日期:2014-09-28 15:11:01青年奥林匹克运动会-五人制曲棍球
日期:2014-09-12 15:36:032014系统架构师大会纪念章
日期:2014-08-04 09:33:532013系统架构师大会纪念章
日期:2014-08-04 09:33:53
15#
 楼主| 发表于 2013-8-6 09:47 | 只看该作者
今天最后一个内容是推荐一个人和2个网站:
CSDN ID: zzxxbb112 赵旭斌
1 QTP系列博客 http://blog.csdn.net/zzxxbb112/article/details/4543102
2 iquicktest http://www.iquicktest.com/unplugged-chinese-edtion-03.html

希望有天我也能做到这个级别的讲师,嘻嘻...

使用道具 举报

回复
论坛徽章:
1056
紫蜘蛛
日期:2015-09-22 15:53:22紫蜘蛛
日期:2015-10-15 13:48:52紫蜘蛛
日期:2015-10-15 14:45:48紫蜘蛛
日期:2015-10-15 14:47:47紫蜘蛛
日期:2015-10-15 14:48:45九尾狐狸
日期:2015-09-22 15:53:22九尾狐狸
日期:2015-10-15 13:50:37九尾狐狸
日期:2015-10-15 14:45:48九尾狐狸
日期:2015-10-15 14:47:47九尾狐狸
日期:2015-10-15 14:48:45
16#
发表于 2013-8-6 12:21 | 只看该作者
thanks for sharing

使用道具 举报

回复
论坛徽章:
1056
紫蜘蛛
日期:2015-09-22 15:53:22紫蜘蛛
日期:2015-10-15 13:48:52紫蜘蛛
日期:2015-10-15 14:45:48紫蜘蛛
日期:2015-10-15 14:47:47紫蜘蛛
日期:2015-10-15 14:48:45九尾狐狸
日期:2015-09-22 15:53:22九尾狐狸
日期:2015-10-15 13:50:37九尾狐狸
日期:2015-10-15 14:45:48九尾狐狸
日期:2015-10-15 14:47:47九尾狐狸
日期:2015-10-15 14:48:45
17#
发表于 2013-8-6 12:22 | 只看该作者
crazypeter2005 发表于 2013-8-6 09:16
1.4 Automation Framework Workflow

We have seen the primary features of our automation framework a ...

这代码 的格式可以适当的调整一下,现在不方便阅读啊

使用道具 举报

回复
论坛徽章:
1056
紫蜘蛛
日期:2015-09-22 15:53:22紫蜘蛛
日期:2015-10-15 13:48:52紫蜘蛛
日期:2015-10-15 14:45:48紫蜘蛛
日期:2015-10-15 14:47:47紫蜘蛛
日期:2015-10-15 14:48:45九尾狐狸
日期:2015-09-22 15:53:22九尾狐狸
日期:2015-10-15 13:50:37九尾狐狸
日期:2015-10-15 14:45:48九尾狐狸
日期:2015-10-15 14:47:47九尾狐狸
日期:2015-10-15 14:48:45
18#
发表于 2013-8-6 12:29 | 只看该作者
crazypeter2005 发表于 2013-8-6 09:26
今天给希望做自动化测试的人推荐2本书:

第一本已上传!
http://www.itpub.net/thread-1807813-1-1.html

使用道具 举报

回复
论坛徽章:
64
罗罗诺亚·索隆
日期:2017-09-07 16:40:52itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03itpub13周年纪念徽章
日期:2014-10-08 15:19:03祖国65周年纪念徽章
日期:2014-09-28 15:11:01青年奥林匹克运动会-五人制曲棍球
日期:2014-09-12 15:36:032014系统架构师大会纪念章
日期:2014-08-04 09:33:532013系统架构师大会纪念章
日期:2014-08-04 09:33:53
19#
 楼主| 发表于 2013-8-6 15:16 | 只看该作者
AlexQin 发表于 2013-8-6 12:22
这代码 的格式可以适当的调整一下,现在不方便阅读啊

调整了...这格式调整还是忒麻烦啊。
斑竹哪儿能搞个汽车的章子啊,哈哈

使用道具 举报

回复
论坛徽章:
1056
紫蜘蛛
日期:2015-09-22 15:53:22紫蜘蛛
日期:2015-10-15 13:48:52紫蜘蛛
日期:2015-10-15 14:45:48紫蜘蛛
日期:2015-10-15 14:47:47紫蜘蛛
日期:2015-10-15 14:48:45九尾狐狸
日期:2015-09-22 15:53:22九尾狐狸
日期:2015-10-15 13:50:37九尾狐狸
日期:2015-10-15 14:45:48九尾狐狸
日期:2015-10-15 14:47:47九尾狐狸
日期:2015-10-15 14:48:45
20#
发表于 2013-8-6 15:24 | 只看该作者
crazypeter2005 发表于 2013-8-6 15:16
调整了...这格式调整还是忒麻烦啊。
斑竹哪儿能搞个汽车的章子啊,哈哈

送你一辆比亚迪~

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表