Banking software testing: design and analysis of testing framework based on Internet financial platform

At present, the Internet finance is in a mess, and the project of automated testing based on the Internet financial platform is also in full swing. The author is responsible for the development of a test framework for a p2p project, so how to design an effective test framework has become a necessity for work and mutual exchange of test experience.

The background of this website is mainly php and java, that is to say, some basic services, such as recharge and cash withdrawal, bidding and repayment, are written using the framework of spring mvc, and then php calls the java API, and the java platform passes The interceptor maps the http request passed by php to the corresponding controller, and the controller is then mapped to the corresponding service and implementation through the map.

Simply put, the website framework is similar to the following:
insert image description here

Some basic services of the website, such as registration and login, user center, investment, red envelope, etc., are triggered by the user’s front desk to trigger php calls, and some activities, red envelopes, gift coupons, etc. are triggered by the background to trigger php calls. .

When selecting an automated testing framework based on such a platform, the author considered the following:

One is to use a framework based on selenium and integrate thinkphp to write. The main principle is to use the firefox plug-in of selenium to record the html elements and javascript scripts on the page, and then do two encapsulations to encapsulate these recorded elements and js into standard objects one by one, save them in the standard object library, and then Add some database data preparation and data cleaning functions, as well as database addition, deletion, modification and query statements.

Then in the engine script, refer to and call the methods of these objects, such as edit, type, etc., and then add loops and some judgments when the page jumps to detect whether the value of the page element exists, or to detect some The return value of the method, or the use of assertions to process the results of the database query and the results returned on the page to match, you can introduce thinkPHP or YII framework to speed up the development of scripts when using selenium as the basic framework.

The other is to use QTP, and its basic principle is similar to that of selenium. The only difference is that QTP provides a good and powerful basic class library, as well as a good object recognition mechanism obeject Spy, QTP There are basically everything in the basic class library, java, .net, web, and even dephi...

When identifying objects, you can map directly through the classes in java, or you can directly use the classes in the web-related class library, or even the windows platform classes... QTP provides a variety of identification methods to help locate objects, so you only need to modify A small number of object attributes can achieve twice the result with half the effort when playing back scripts and editing core codes, but QTP also has disadvantages, that is, it is inconvenient to handle Js, and it is necessary to start QTP at all times, and cannot be used with some open source tests. The framework, especially the java open source project, realizes the integration of automatic deployment of test cases and automatic packaging.

The principle of ruby ​​+watir is similar to that of selenium. It is also an automated testing framework based on WEB GUI. The author has done little research, so I won't say much.

However, due to the characteristics of the p2p industry, these web-based automated testing frameworks have many unsuitable places. These related functions related to investment recharge and withdrawal are more concerned about not only the display of some element functions on the page, but also the is the correctness of this data.

If you use a GUI-based method for automated testing, I personally feel that the identification and verification of page elements often cannot reflect the correctness of the data, and when dealing with abnormal page elements, it is often impossible to do strong for complex business logic and data. Processing and benefits, and the GUI simulates manual processing, which is also less effective in terms of execution efficiency, and if a certain page element cannot be recognized or is abnormal, it may interrupt the processing of the entire page. When analyzing the code coverage, based on The way the web is not so easy to analyze.

In the current project, java mainly provides restful applications based on the HTTP protocol to the PHP platform. The reason why restful is used instead of webservice to process data transmission is because webservice uses json instead of xml to process data transmission. Compared with restful, it is also heavier. JSON also needs to be encrypted, decrypted, parsed, and serialized. In restful, you can directly operate on resources through http requests.

Therefore, the author thinks that it is more direct and effective to directly test the interface from the controller layer, and considering that the spring framework provides a mock http request method, and the correctness of the web UI is not so high in priority to the correctness of the background business data , and in the spring test framework, although the correctness of the controller can be verified by asserting the ModleAndView object returned by the controller layer, that is, the interface test can be used to benefit the results, but if there are too many objects behind the controller layer, once a problem occurs, it is not easy to troubleshoot wrong.

Therefore, the basic idea of ​​the test framework is to use the mock restful tool class provided by spring mvc, and then introduce the assertion mechanism and database processing to analyze the correctness of business logic and data correctness of each controller. The sping MVC itself also provides a set of testing frameworks, which can be tested separately through server-side testing and client-side testing.

Before the server test uses the spring mvc test framework, it may take code similar to the following:

@Test

public void serverSample() {

MockHttpServletRequest request = new MockHttpServletRequest();

ModelAndView mav = new sampleController.function(parameters);

ModelAndViewAssert.assertViewName(mav, user/view);

ModelAndViewAssert.assertModelAttributeAvailable(mv, user);

}

}

After using the server-side test, you can use the following two methods:

standalone:

public class ServerTest {

@Autowired

private MockMvc mockMvc;

@Before

public void init() {

SampleController sample = new SampleController();

mockMvc = MockMvcBuilders.standaloneSetup(SampleController).build();

}

}

  Integration:

public class ServerTest {

@Autowired

private WebApplicationContext wac;

private MockMvc mockMvc;

@Before

public void init() {

mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();

}

}

 Test:

@Test

public void testSample() throws Exception {

MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get(/user/1))

.andExpect(MockMvcResultMatchers.view().name(user/view))

.andExpect(MockMvcResultMatchers.model().attributeExists(user))

.andDo(MockMvcResultHandlers.print())

.andReturn();

Assert.assertNotNull(result.getModelAndView().getModel().get(user));

}

The above is the server-side testing method using spring MVC. As for the client, there are several methods.

1. Start the container through jetty, and actually map to the controller layer for implementation;

2. Use spring boot test

3. Use mock service server to test, the third method is basically a better way to use resttemplate to test the client;

That is, first create the Mock Server of RestTemplate through MockRestServiceServer, and then add the client request assertion to judge whether the assertion requested by the client is correct. 3. Add the server response to check whether the server response is correct.

There are also many resources on the Internet for client-related codes, so I won’t go into details here. Here is mainly to provide an idea of ​​how to test the controller layer based on the spring mvc framework and restful applications.

Finally, I would like to thank everyone who has read my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, you can take it away if you need it:【保100%免费】

insert image description here

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can do quizzes on your mobile phone, on the subway or on the bus, roll it up!

The following interview question sections are covered:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. web, app, interface automation, 7. performance testing, 8. programming basics, 9. hr interview questions, 10. open test questions, 11. security testing, 12. computer basics

Document acquisition method:
This document and video material should be the most comprehensive and complete preparation warehouse for friends who want to engage in [software testing]. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. Hope Can help you too! All of the above can be shared, click the small card below to receive.  

Guess you like

Origin blog.csdn.net/NHB456789/article/details/132210068