当前位置:网站首页>Pytest automated test - easy tutorial (01)

Pytest automated test - easy tutorial (01)

2022-06-11 06:43:00 zhulixinxikeji

What we are going to talk about today , Is the testing framework Pytest, Speaking of this testing framework, I haven't done Web For automation partners , Will feel this thing is strange , So what exactly is a framework ? What is automation ? Why should automation use frameworks ?

Don't I just learn automation Python+Selenium perhaps +Appium Is that all ?

What is the function of this framework ?

In the middle of this process , Let me tell you about automated testing first ,

So called automated testing , You can understand that it is actually the same as the function test process , For example, when we do functional tests , What do you need to do ?
You need to analyze the needs .

A functional test : Analyze requirements ==》 Design of use cases ==》 Execute test cases manually ==》Bug Submission of ==》 Test report

When we do functional testing, we should first analyze the requirements , Then we need to design use cases , In addition, execute the use cases manually , Then, we also have to carry out Bug A submission for , If you come across Bug We are going to submit Bug, End of submission Bug after , After testing a version or a phase, we will issue a test report . Basically, for our functional testing, it is such a process .

automated testing ( Analyze requirements ==》 Design automation use case control ==》 Code ( Tools ) Execute use cases )==》 Test report

In fact, automated testing is also a part of this process , First, we will also analyze the requirements , But the analysis requirements , It refers to your needs for the whole project business , And process requirements . I want to determine which businesses are involved in this project 、 Processes can be automated , What cannot be achieved , What can be achieved is done automatically , If you can't do it, do it by hand . So in the first stage, we all do demand analysis , Then in this area, you need to design automated test cases after you determine the requirements , In this , What do we mean by automation ?

That is to say, we use code or tools instead of human to execute the process of this use case , So it's automated testing .
Because in the middle of the functional testing work , Originally, we did it by hand , Click input and other operations , Only in the automation process, code or tool methods are used to replace .

How the code tool executes , How to judge , How to submit test reports , So we write all these things in the middle of the code , Because in the middle of this process , Since you have written so many test cases , When the code is implemented, we will also cover the automated test cases , So as to realize . The test report will be issued later , But this test report doesn't need you to make statistics manually .

For example, I make statistics manually , How many altogether Bug,A How many classes are ,B How many classes are ,C How many classes are , Whether the test result is passed or not , This is the way we make statistics when we do function tests , To measure .
But when doing automated testing , We can also use the form of code , Let it generate the specified test report , In the middle, you will automatically count how many test cases are successful and how many test cases are failed ( Wrong )

So in this area, functions and automated processes , The biggest difference is in the code ( Tools ) Execute the use case

So if we want to use code or tools , To cover or complete all automated test cases , How do we do it ?

Are they all done in a linear process ?

Linear process : Open the browser -- Enter the login interface -- enter one user name -- Input password -- Click login

Sign in

  • 1: Correct user name Admin, The right password -123456 ==》 result ==》 Write it in the test report

  • 2: Wrong user name User, Wrong password -1234567890

  • 3……

Whether it's your first or second use case , What it does is a linear process like the previous one , What is the biggest difference between them ?-

The biggest difference is the data :

  • For example, the correct user name Admin - 123456
  • If I'm wrong, I'll do it User, Password matching 123456
  • Or the correct user name Admin, Match a wrong password 1234567890

So here we have to consider , How to maximize the reuse of scripts , As long as it is implemented through different data OK, And after each use case is executed , It will automatically generate corresponding results for you , Write it in the middle of our test report . Because we finally judge whether you pass the automated test or not by the results in the test report .

So in this case , How to solve this problem of use case coverage , So I have to tell you , We need to address use case coverage , It's ours

Unit test framework

For example, we often

  • Java——junit
  • Python——unittest / Pytest
    These frameworks are designed to standardize the coverage of automated test cases , And reuse scripts to the greatest extent .

In the middle of the process , The unit test framework can not only be used in the middle of our automated test process , It can also be used as a white box test in the unit phase , This means that we test engineers do not have much contact with this part of the work , Because among enterprises , Most white box tests are done by developers . Just say that if you master this thing , Besides, we can use it in automation , It can also be used in unit white box testing .

What I want to tell you today is Pytest.
unittest / Pytest What's the difference? ?
Let's briefly explain ,
The first thing they have in common is that they are both mainstream unit testing frameworks

Some friends, like him, only know one of them , For example, you will Pytest But it won't work Unittest.

In fact, this is also an interview question : Why do you use this one instead of the other ,unittest / Pytest What's the difference? ?

In our learning process , Since these two are the mainstream , Basically, we have to know both frameworks .

Unittest yes Python It comes with a unit testing framework , and Pytest Is a third-party framework , This is the first difference between the two .

The difference between the built-in framework and the third-party framework ?

The self-contained does not need to be installed , You can use it directly , Third party you have to install first .

Second difference ,Unittest In fact, there is no function of Pytest So powerful , because Pytest It has many plug-ins , And the overall situation is very good .

The third difference ,Pytest The implementation will be better than Unittest More concise , Lighter .
So when we build an automation framework among enterprises , In fact, I will choose Pytest More than that Unittest.
however Unittest For beginners , It is also a very good framework .

原网站

版权声明
本文为[zhulixinxikeji]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110639185137.html