How to develop a testing framework?

basic concept

  • The English word for library  is Library. A library is a product that is a collection of codes for programmers to call. The library formed by object-oriented code organization is called a class library, and the library formed by process-oriented code organization is called function library.

  • The English word for framework  is Framework. A framework is a product developed to solve one or a type of problem. Users generally only need to use the classes or functions provided by the framework to realize all functions.

  • The English word for tools  is Tools. In my opinion, tools and frameworks do similar things, except that tools provide a higher level of encapsulation, shield the underlying code, and provide a separate operation interface for users to operate. For example, UFT (QTP) and Katalon are automated testing tools.

Common libraries

According to the above concept, Requests is HTTP库, please see the official introduction.

Requests is an elegant and simple HTTP library for Python, built for human beings.

Its usage is like this:

import requests
r = requests.get('https://api.github.com/events')

So, in fact, Selenium Webdriver is just one.

from selenium import webdriver
browser = webdriver.Firefox()

browser.get('http://www.yahoo.com')

Note: I am not talking about the entire Selenium tool. The entire Selenium includes: Selenium IDE, Selenium Grid, Selenium Webdriver, etc.

We only need to use a certain class or function in the library to complete the function we want to achieve.

Common frameworks

Let’s talk about the framework, called unittest 单元测试框架, please see the official introduction.

The unittest unit testing framework was originally inspired by JUnit and has a similar flavor as major unit testing frameworks in other languages. It supports test automation, sharing of setup and shutdown code for tests, aggregation of tests into collections, and independence of the tests from the reporting framework.

So, this is what we do when using unittest.

import unittest

class TestStringMethods(unittest.TestCase):

    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')


if __name__ == '__main__':
    unittest.main()

This should be the simplest test case written.

Django is called  Web开发框架, I think you should have no objection.

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py
    polls/
        __init__.py
        admin.py
        apps.py
        migrations/
            __init__.py
        models.py
        tests.py
        views.py

This is the directory structure of a framework. Even if I just want to use django to display a line of "hello world" on a Web page, it will also involve coding multiple files.

The cost of learning and using the framework is higher. If we want to use the framework, we may need to use multiple classes and functions it provides, and we must also follow its code structure or directory structure.

Common tools

Tools are easy to understand. Postman, JMeter, fiddler...these that need to be downloaded and installed are generally called tools. This is not the point of our discussion.

The birth process of a framework

Back to the topic of frameworks, generally the birth process of a framework will go through three stages.

  • Learning to use it
    usually means reading the official documentation of the framework. First, install it, and then use it to do projects. This has been used for many years. For example, I have been using Django for several years, but I have never fully read its official documentation, let alone read and used its source code.

  • Read the source code.
    Generally, if you are a bit good at it, or you have rich experience in development, you certainly don’t want to be limited to the use of the framework. They will spend weeks, even months, reading the source code of the framework. This helps to deal with and troubleshoot various problems during the use of the framework.

  • Self-study framework
    To be able to self-study a framework, in addition to talent, you also need opportunities. For example, your company has extremely high requirements for performance, and all open source or commercial frameworks cannot meet your needs. So I embarked on the road of self-research, analyzed the performance bottlenecks of the entire framework, replaced key modules with higher-performance languages, or implemented key functions with better algorithms.

Alibaba’s dubbo is called a framework. No one should object, right?

Apache Dubbo™ is a high-performance, java based open source RPC framework.

Automated testing framework

What our testers say 开发自动化测试框架 is that in most cases:

  • python + unittest + HTMLTestRunner + page objects

  • python + pytest + allure + page objects

Developers.... ? Isn't this what I use:

python + django + pymysql + HTML + CSS + JavaScript implement a Web system

Isn't this called "project development"? You just take a bunch of ready-made things and integrate them together to achieve the certain function you want. This is called  项目开发, not called  框架开发.

robot framework is a framework

Robot framework is of course an automated testing framework.

Robot Framework is a generic open source automation framework for acceptance testing.

Why can it be called a framework? Just because it has a "framework"? Of course not, because it implements a whole set of automated testing things.

  • How to write use cases
  • How to organize use cases
  • How to run test cases
  • How to count use case results
  • How to generate a test report
  • How to extend the test library

If the above are all designed and packaged by yourself, then you can also say that you have developed an automated testing framework, but you clearly use unittest/pytest but say that you developed the automated testing framework yourself! Either misled or shameless.

Can development frameworks be taught?

So the question is, can someone teach you how to develop a testing framework?

Are you asking the master to teach you how to develop one  前端框架 ? Well, he can tell you about the use of Vue.js in the project, or if you are a front-end development expert, you can sit down and talk about the design ideas of Vue.js. You can also participate in vue.js project maintenance.

You asked debugtalk to teach you how to develop an interface automation testing framework? Well, he can tell you about the techniques for using HttpRunner in projects. If you have many years of experience in interface testing, you can also provide some opinions and exchanges.

You are a novice in testing, but you have to "develop a testing framework" at first, and do you want others to teach you how to develop it? Why don't you go to heaven?

[Full 200 episodes] A collection of super detailed advanced tutorials on automated testing of Python interfaces, truly simulating the actual combat of enterprise projects.

Guess you like

Origin blog.csdn.net/dq565/article/details/132806959