with the company's various departments on the importance of quality, API testing has become one of the daily test tasks, in order to improve testing efficiency, reduce repetitive manual operation, API Automation testing has become increasingly important, this article is their own in the API Automation testing experience accumulated and experiences, summary of the written, Readers What is the API, I think the narrow understanding of the API is the system of external exposure of some interface, for the system internal other modules or external systems to call, such as TD, Harvest have their own external exposure of some APIs, to be on its basis for two development, This article is only for the Loushang platform API to tell, the current Loushang platform main API mainly focus on the BSP and BPM two modules, about 300. before introducing API Automation testing, it is necessary to first introduce the traditional API testing, so-called traditional API testing is similar to traditional manual functional testing, for a function point or business scenario, to prepare some data, to perform the test, the advantage is that the test speed, But the shortcomings are also very obvious, can not be automated, can not be repeated, the need for manual real-time operation, the function of automated testing is relatively simple, there are many automated testing tools available to choose from, such as QTP, Rational Function test and so on, the API Automation test threshold is relatively high , one is the right tool less, the second is the need to understand the use of the API test scenario, the third is the need to thoroughly understand the API code logic and background data structure, and be able to design the corresponding test data to cover a variety of business scenarios and code branching structure. 工欲善其事 its prerequisite, before doing API Automation testing, also need to use some external tools, and then according to the needs of their projects, external tools can be adapted to suit their needs. To do API Automation test first need to master the relevant programming language, in terms of Loushang platform API, Java language Proficiency is essential. There is a very popular and popular test framework in the JUNIT4,JUNIT framework that provides many assertions, and useful annotations, which are prerequisites for automated testing. In addition, Ant provides a good support to JUnit, can generate test reports, users can, as needed, to transform the ant-junit, such as the test report to the Chinese, add some of their own attention but the report does not have some information. 90% above the API is to deal with the database, testing how to prepare? How does the database recover? This is also a major challenge for automated testing, and it is recommended that you use Dbunit,dbunit to export your database tables to XML and XLS files intoBackup, while supporting the import of XML, XLS data files into a database table, before testing, such as in the before phase of the JUnit test case, the related database tables are backed up, and the test data (usually in XLS or XML file) into the corresponding database table, after the test case execution is completed, Restore the backed-up database table back to the database, so that a separate test data and test code is implemented, and the second ensures that the data in the test database is not affected. in the import and export of data, sometimes quite affected by foreign key constraints, such as testing an API, the API only 2 database tables, but there are n other tables with these 2 tables there are foreign key constraints, ready to test the data, it is very troublesome, recommended to perform testing, If necessary, the foreign key constraints of the database can be temporarily disabled, after the test, and then the FOREIGN key constraint is enabled, as for the method of enabling foreign keys, disabling foreign keys, different database mode is not the same, the reader can self-study. api test, sometimes encounter some unimportant objects, but these objects are very difficult to construct and test the interface and inseparable from them, such as ResultSet, request, session, etc., you can use object simulation technology, such as Easymock, Jmockit, etc., very useful. api test is a white box test, in order to more clearly show the test coverage, the general test is completed, out of the test report, there will be a test coverage report, the industry has a number of test coverage tools to choose from, such as Cobertura, Cobertura will generate a very beautiful test coverage report, and readers can look into how to integrate with their own test environment. test reports, test coverage reports generated, are generally some HTML files, API Automation testing, due to the occasional task (can take advantage of Windows Timer task or self-developed Java timer) automatic execution, The test report needs to be sent to the relevant testers by mail, so we also need to master the packaging tools (ant has been provided, can be used after simple packaging), Mail sending tool (JavaMail very useful, can be studied). at this point, the API Automation testing requires a basic introduction of the technology, some items personalized things (such as login simulation, SCA service loading, spring container loading) also need to study according to actual needs, comb the whole process as follows: windows Timer task or self-developed timer----"Execute bat Batch command----" bat call ant----"Ant execution JUnit Test Case---"After the execution of the test report and test coverage report into a ZIP compression package---" Send the package as an attachment message attachment to the relevant person. development, in order to further improve the test architecture, simplify the test code writing, you can consider the use of the Unitils framework, unitils integration of JUnit and easymock, can effectively simplify the writing of test code. Summary, this article is based on their current testing process and framework as a blueprint for the compilation, hoping to be interested in the API Automation testing colleagues to provide some help and reference!