Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to automatically generate test cases for Python automated testing

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you about Python automation testing how to automatically generate test cases, the editor feels very practical, so share with you to learn, I hope you can learn something after reading this article, say no more, follow the editor to have a look.

Today, Shaanxi excellent Employment Xiaoyou sorted out some technical practical knowledge, learning software testing partners, you can come to have a look, are some basic knowledge, I hope it can be helpful to your study!

Traditional test cases require tests or developers to express users' actions in code, and it takes part of time to write test cases through assertions to determine whether they are consistent with expectations. In addition, the maintenance cost of version iterative test cases is also high. therefore, based on non-buried point requirements combined with automated testing to detect buried points, timely alarm, improve accuracy and code quality. In order to reduce the development and maintenance time of test cases, a scheme is born to generate test cases automatically, and the execution of the code is not interrupted because of errors.

Testing framework:

The test framework uses FAutoTest to test Mini Program and H5. Compared with the selenium used before, the code runs much more stably, and the time of wait is also very stable. Compared with phantom screenshot pixel comparison, you can refine the behavior of the test case. Driver based on X5 kernel can test Wechat environment and cover the current business usage scenarios.

How to generate test cases automatically?

1. First of all, configure the test case in the background.

Get the click location xpath, the expected copy or style of the test case

Request the interface to write the test case data configuration to the table and provide the interface to pull all the test case data

two。 After configuring the test case, the python request API gets the input parameter (in field) and output parameter (out field) of the test case configuration. The field in in is the input parameter, url is the page where the click behavior is located, xpath is the click location, the field in out is the output parameter, url is the expected page to be redirected, xpath is the tag location of the expected page, with text is the expected copy, and with class is the expected style. Split user behavior into parameters as far as possible. The behavior that can be expressed by parameters.

The 3.python request interface traverses the interface data to generate test cases prefixed with test_case_xxx, and automatically generates test cases instead of executing all the actions in a test case to avoid interrupting code execution due to errors.

Generate a test report:

1. Install HTMLTestRunner

HTMLTestRunner is an extension of the unittest module of the Python standard library, which can generate HTML test reports.

two。 Introduced into the test script

From HTMLTestRunner import HTMLTestRunner

3. Define the path to the test report and call HtmlTestRunner

4. Execute test scripts, print test reports, and generate html.

5. Execute the test script again to generate the test report.

The above is how Python automated testing automatically generates test cases, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report