As cloud computing and SOA and agile software development are in full swing, the demand for test engineers is growing. At present, many companies, especially internet companies have carried out the work of interface testing, with the increasingly complex web architecture, the variety of interfaces, there are http,webservice,hessian,dao,message and simple API interface, So how to design or select a test framework to complete the test of these interfaces has become a big challenge. This article will briefly introduce a Java developed open source test framework FitNesse in the interface testing, and enumerate some simple demo for demonstration and explanation.
FitNesse is a lightweight open source framework that can help develop and test teams to easily define interface acceptance tests (acceptance Tests). FitNesse supports the testing of multi-language software products, including (java,c,c++,python,php) and so on. Specific use can refer to: http://www.fitnesse.org/.FitNesse.UserGuide, because the introduction of FitNesse tools is not the main purpose of this article. In the FitNesse framework, a total of three parts are included, Wiki,test system,fixtures. The wiki section will show specific test cases and test suite even test requirement,test system including two parts of Slim,fit, the FitNesse execution engine, Fixtures is the real test code. The FitNesse concrete schema diagram looks like this:
As you can see from the diagram above, the test cases about business logic are described in wiki pages, and FitNesse will resolve the test cases that wiki pages transmits, based on your choice of test System (slim or fit). If we chose slim as our test system, then slim runners would convert the wiki script from the network to a series of instructions and then slim Executer will parse and execute these instructions to invoke the test code we have written, that is, fixtures code,fixtures can be Java language test code, c language test code, or other language-written test code that will invoke the object being tested to execute the test case. Similarly, the same is true when you choose Fit as Test runner, but fit is not the same as slim when parsing a wiki script, fit will use the wiki page as HTML and then parse the HTML page to invoke the background test code to execute the test case. Relatively poor performance relative to slim. In addition, when using fit, design test code must inherit the Fit class to write, relatively slim test code writing relatively limited. So I recommend that you use Slim, because slim will be more lightweight and efficient, in the past two years, our team has been using slim as Test Runner, and on the basis of the slim has done a lot of two times development and improvement, relatively stable.
We can use FitNesse to do unit testing, integration testing, interface testing and other related tests. This article focuses on the use of FitNesse in interface integration testing, less nonsense, the following main course, in the following example, the FitNesse Slim will be used to do Testrunner, interface testing in the Java environment.
HTTP interface Test
You can use a Third-party tool Httpclient.jar to write HTTP interface clients to send request. Here we do a simple HTTP interface test, such as testing the Infoq login interface.
First write the test code as follows:
1. Send POST request:
(1) Set request parameters
The method has two parameters the first parameter is the map type that represents the request form parameter, and the second parameter is used to represent the number of form parameters, where parameters is a Namevaluepair array and is set as a global variable.
(2) Send request
The method parameter is the service-side return value for the request url,postresponse.
(3) Check return value
Of course, the postresponse here may have to do some specific parsing based on the checkpoint of the business requirements and do not make detailed parsing in this use case.
Then use FitNesse to design test cases and execute tests:
(1) Set table environment variables, specify the use of Slim as Testsystem, and define classpath to facilitate fitnesse to drive test code execution cases.
(2) Define test data, such as the submitted form data username and password, we are used to test the Infoq login function.
(3) Define the expected output value, after the login Infoq success, the server return parameter will return the "OK" string, which is used to describe the success of the login scenario.
Click the Test button to perform the case result as follows:
The use case has a checkpoint, that is, when you call the Checkpostresponse method, enter the expected value OK, the method checks the return string to find the string, so the test case passes, test case pass, so the execution result is green.
You can design additional test cases by simply changing the parameters to form a test set of the Infoq login feature.
This section focuses on FitNesse testing of HTTP interface types.
WebService Interface Automation test
Most Internet companies now adopt an SOA architecture, so testing for WebService interface types is more important. Typically, test engineers may use tools such as SOAPUI to test Web service, undeniably soapui have very good results in a single WebService interface test, but in the interface combination test, And when the test results need to be verified by the database is not so automated, always require manual intervention, which in part leads to low test efficiency, so we are here to explain how to use FitNesse this open source product implementation Interface test Automation.
First of all, we simply built a webservice demo.
The WebService interface consists of a total of 4 methods, and we will test the scenario of the two methods, Addusertotheworld and Getuserfromtheworld.
First, design test code, thinking and HTTP interface test, design WebService client-side send request, using spring and CXF design WebService client side, It is also possible to generate client code with CXF or axis's own client-side build tools, but it is recommended that you write the client yourself so that the code is simple and clear.
The Spring context configuration is as follows:
The client test code looks like this:
Let's look at how to design the case in FitNesse to describe the above code:
The test case description looks like this:
The use case described in the above illustration is used to call the Testaddusertotheworld method to join the user to the database, and then call Testgetuserfromtheworld to remove the relevant data from the database. In this way, as a combination of scenes called WebService Addusertotheworld and Getuserfromtheworld These two methods, of course, can also design more scenarios to test, if the use of soupui at least two times to do the operation, If there is a need for database checking, it may take 3 operations, and it is not easy to automate. Next let's take a look at the results of the use case execution.
The execution results are passed by the test execution as shown above. Let's take a look at the scenario where the use case failed:
We changed the age value of the expected output to 27, the test case execution failed, and the actual result did not match.
Database Checksum test
Let's discuss the database verification test, the open source community has a lot of relevant database testing tools such as Dbunit, as well as the Fitnesse/fit test engine dbfit are very good tools, the author according to the Dbfit function design fitnesse/ Slim test engine Dbslim, to facilitate the operation of the database test.
Dbslim currently has the function of screening, support for Oracle, MySQL, SQL Server operations, source has been uploaded Google.code Open source, specific in the fitnesse of the use of the scene as follows:
Use Dbslim first to set the relevant environment variables, because the use of MAVEN to do the management of the code, so you need to configure the use of the dependency as shown above. There are three wiki tables in the diagram above, the first table is the name of the package referenced, the second table is used to connect the database, we use MySQL so we call the Connecttomysql method, and then configure the database URL and port number, database name, username and password. The third table is a few improvements to FitNesse's query table, which is used to query the database, Query:query is the writing method of the query table, the first one is the keyword of the lookup table, The second query refers to the query class in the call Dbslim, followed by the SQL to query. The second row of the table represents the field to query and the query field one by one in SQL, and the third row represents the expected value, which makes up a scene of a database query operation. You can also refer to the FitNesse Official User Guide for the use of tables in FitNesse. Let's take a look at the execution results:
This article only describes the query operation, other operations are not introduced.
Summarize
This article mainly introduces the use of FitNesse in interface testing and integration testing, from the above demo can be seen, using FitNesse interface test, there are the following advantages:
1. The test code writing is simple, the style is free.
2. Test code and business logic separation, FitNesse above only responsible for business story writing, test code and business use cases to facilitate maintenance.
3. Test code redundancy greatly reduced, the same test code can be composed of multiple business scenarios to use.
4. FitNesse is a complete Java development Testing framework, cross-platform and easy to merge with other test frameworks, the author has done FitNesse and testng,junit and selenium integration.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.