In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to write interface tests in Java". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to write interface tests in Java" can help you solve your doubts.
1. Interface testing
Interface: mainly the interaction and interaction between sub-modules or subsystems.
The interface here is in a broad sense, the protocol between the client and the background service; the interface for communication between plug-ins; the interface between modules; and then as small as the method provided by a class; can be understood as an interface. Therefore, it can be analyzed that the interface between systems consists of three parts: input, processing logic and output.
Interface testing: refers to the testing of modules or inter-system interfaces.
2. How to analyze an interface?
Get the interface document: like the black box test, we mine the test points from the requirements document and design the test case. For interface testing, there is also a corresponding interface document.
Analyze the interface documents and extract the test points:
1) input: which parameters, types of parameters, optional parameters and required parameters are accepted, and designed according to the input parameters by equivalence class, boundary value analysis, etc.
2) Business logic: for an interface, the process or state transition is different for different input parameters or combinations. You can draw a flow chart or state transition diagram according to the business logic to ensure that each state is accessed at least once.
3) output: reverse design of test data according to the output specified in the document so that all output states are included
Test cases: when considering input, business logic and output at the same time, there must be redundancy of use cases. Under the maximum coverage of business functions and rules, the optimal set of use cases is selected. At the same time, you need to consider exception data and scenarios.
3. How to determine the coverage of use cases?
In the absence of special requirements, at least the following should be considered:
1) whether the business function coverage is complete
2) whether the coverage of business rules is complete
3) whether the parameter verification meets the requirements (boundaries, business rules)
4) whether the coverage of API exception scenarios is complete
If the interface requirements also include performance or security requirements, as well as performance testing and security testing of the interface, we need to consider whether the performance indicators meet the requirements and whether the security indicators meet the requirements.
4. Typical problems found in interface testing
Bug and problems often encountered in interface testing are as follows:
(1) improper handling of input parameters, resulting in program crash
(2) Type overflow, resulting in inconsistent reading and writing of data
(3) because the permissions of the object are not verified, you can access other user sensitive information.
(4) improper handling of the state, resulting in logic confusion.
(5) the logic check is not perfect, and the loopholes can be used to obtain illegitimate benefits.
5. How to write interface test cases?
Create an interface test case:
/ home/csg/pyrequest-master/interface/add_event_test.py
Analyze the above code:
1. Before the interface test, call the init_data () method in the test_data.py file to initialize the test data in the database.
2. Create an AddEventTest test class and inherit the unittest.TestCase class
3. Create a test case, call the add release API, and verify the data returned by the interface
Note:
1. Convert the results in JSON format into dictionaries and assign values to self.result variables. The purpose of adding self is to print self.result variables in the tearDown () method. The printed results can be displayed in the test report, that is, the returned data of the interface is printed out.
2. If you do not use self and want to show the data returned by each interface in the report, you can only print the result in each use case. Compared with the first method, it is more convenient.
Integration test report
When there are a large number of use cases, classified management and execution are needed. In order to solve this problem, the unittest unit test framework provides the discover () method, and then applies HTMLTestRunner to generate test reports in HTML format.
Create a / home/csg/pyrequest-master/interface/run_tests.py file:
Analyze the above code:
1. First call the init_data () function in the test_data.py file to initialize the test data
2. The discover () method provided by the unittest framework finds the test file in the interface directory that matches to the end of the file name * _ test.py
3. Now generates the current time in a certain format
4. Name the file name now current time _ result.html and save it in the report directory
5. HTMLTestRunner is the extension of the unittest unit test framework, using the HTMLTestRunner () class it provides to replace the TextTestRunner () class of the unittest unit test framework, running the test cases matched in discover, and generating the test report in HTML format.
Run the test script: python run_tests.py:
1. You may need to install the configparser library, pip install configparser
2. An error occurred during the operation:
The create _ time field in the data table needs a default value, so modify the test_data.py file to add the create_time default value to each test data to the current time, and there will be no such error if you run it again.
3. However, there is another error in continuing execution:
Asked the next du Niang, should be read the file using ASCII coding, not utf-8, their own superfluous, in each test case at the beginning of the addition of-*-coding:utf-8-* -, lily icing on the cake, removed and run again without this error
4. But the running results are all failed. Check the specific error information:
Originally, we still have to add the declaration of utf-8 coding before each test data, but the comment information of each use case can not be in Chinese, strange, no in-depth study, anyway, after it has been modified to English, it has been run successfully again.
The complete automated test report is shown in the following figure:
After reading this, the article "how to write interface tests for Java" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.