How to write automated test cases

automated test script

What is automated testing?

Automated testing is the verification and verification that software meets all user requirements and functions as expected using automated tools . It checks for bugs, problems, and other types of defects that arise during and after the product development phase. This type of software testing runs on programming scripts that are processed by testing tools. There are various testing tools that either provide a code-based platform or a no-code option for QA.

Why Automate Testing?

Automated testing is critical for many reasons. The main reason is that it saves money and time while executing manual test cases. But the benefits of automated testing don't stop there; it provides a gateway to execute the complex testing process, eliminates possible manual testing errors, and produces consistent, reliable results.

Where manual testing enables humans to analyze the product and create test reports, automated testing is ideal for larger projects that require repeated testing of functionality or that may have already gone through an initial manual testing process.

The overall advantage of adopting automated testing techniques and tools in your business is the introduction of defect-free products with shorter lead times and better productivity metrics. Now we can check below what are all the advantages of automated testing over manual testing.

What is an automated test script

Automated test script, that is, Testing Script, is to complete the function of automated test by writing some script code, which can be written in programming languages ​​such as javascript/java/python/php and not limited to.

What does an automated test script look like? how to write?

We can use a small example to talk about what an automated test script looks like and how to write it.

If I want to use Python + Selenium to test a small page to test whether its input box search function is normal, I can write the code as follows:

These codes are actually automated test scripts, because after you write them, you can let them run hundreds of times and thousands of times, and you don’t have to touch them anymore~

Using automated test scripts in interface tools

The same is true for automated testing of APIs. We can also test APIs by writing code. We need to choose an API tool for automated testing. Today I choose Apifox to complete this  operation  , because Apifox supports automated testing and supports it by default. Chinese.

Create several requests

We need to create several requests, and write the script code in the pre-script and post-script in the request. The default scripting language of Apifox is javascript.

After filling in the path, method, and name, we need to write custom scripts.

Writing custom scripts

We can find that Apifox has prepared many templates for verifying script codes for us.

For example, the following script code:

We can set multiple test verifications for this request, for example, I added two here:

  • Check if the returned status code is 200
  • Whether the request takes less than 200ms

Click Save, we can try to run it first, and we can find that we get the expected effect and the verification has passed.

automated test

Just imagine, if there are five interfaces, it is impossible to send them one by one~ so we need to use the automated testing function of Apifox.

We need to enter the automated test interface, and then import the corresponding interface.

Finally, fill in the environment, the number of cycles, the number of delays, etc., and run.

To get the running results, you can view report parameters such as time-consuming, number of successes, and number of failures.

Knowledge expansion:

Learn more about automated testing.

Guess you like

Origin blog.csdn.net/m0_71808387/article/details/130321794