A 15,000-word article teaches you how to build an interface automation testing framework using Eclipse+TestNG (recommended to collect)

Teach you how to build an interface automation testing framework using Eclipse + TestNG

Teach you step by step how to build an interface automation testing framework using Eclipse + TestNG

Without further ado, let’s get straight to it~

1. Environment installation

1. Premise

Install jdk

Configure Java environment variables

Install Eclips

These are all available online, so I won’t introduce them in detail.

2. Install the TestNG plug-in

Online installation is slow due to network speed. The following is the offline installation method.

(1) Unzip the eclipse-testng offline package.zip

(2) Copy the folder org.testng.eclipse_6.8.6.20130607_0745 in [eclipse-testng offline package/feature] to the [MyEclipse installation directory/features] directory

(3) Copy the [eclipse-testng offline package/org.testng.eclipse_6.8.6.20130607_0745] folder to the [MyEclipse installation directory/plugins] directory

(4) Restart MyEclipse, Windows – show view – TestNG

3. Install Ant

(1) Unzip apache-ant-1.9.6-bin.zip to any directory

(2) Configure the Ant environment variable and add: /bin; at the end of the Path variable;

2. Create a Java project in Eclipse

1. Eclipse -> File -> New -> Java Project, as shown below, fill in the Project name in the pop-up window and click Finish to complete the creation of the project.

2. Import related jar packages:

Right-click on the project -> Build Path -> Configure Build Path…, as shown in the figure below, to open the Build Path configuration window.

Import the installed TestNG plug-in and complete the import of testNG as shown in the figure below:

3. Download lib.zip from the resource sharing link, unzip it, and import the jar package inside as shown below. These imported jar packages will be used in the program.

Now I have also found a lot of test friends and created a communication group to share technology, sharing a lot of technical documents and video tutorials we collected.
If you don’t want to experience the feeling of not being able to find resources when studying on your own, having no one to answer your questions, and persisting for a few days before giving up.
You can join us to communicate. And there are many technical experts who have made certain achievements in automation, performance, security, test development, etc.
Share their experience, and also share many live lectures and technical salons
You can learn for free! Focus on it! Open source! ! !
QQ group number: 110685036

3. Use TestNG framework to write test cases

1. Create the src folder to store test-related code. Right-click on the project -> New -> Folder and fill in the file name: src.

2. According to the principles of separation of data and code and extraction of public methods, my code structure is divided as follows:

3. Script writing sequence

3.1 Global configuration file (GlobalSettings.java)

Store some project global variables, such as baseUrl, timeout, etc.;

3.2 Http protocol implementation (HttpClientHelper.java)

Implement relevant requests according to the protocol used by the project interface. Our project has two methods, one is to use NameValuePair to encapsulate request parameters, and the other is to use JSONObject to encapsulate request parameters, so we have code implementations for both methods.

3.3 Interface implementation (GList_API.java)

Take “Create G Order” as an example to implement this interface:

3.4 Prepare test data (TestData.java)

Prepare test data for the interface.

3.5 Test data parameterization (GListDataProvider.java), the number of returned parameters needs to be consistent with the number of function parameters in testsuit.

3.6 Test case suit (GListCURD.java)

4. Test case debugging and execution

After writing all the use cases according to step three, you can debug and execute the use cases.

4.1 Test case script debugging

Right-click on the test case suit GListCURD.java in step 3 and select “Debug as” or “Run as” -> “TestNG Test” to run the script.

4.2 Test case script execution

There are two ways to run this script, testNG or ant.

Run using testNG as in step 4.1.

To run using ant, you need to create xml. Please refer to build.xml and smokeTest.xml in the resource library. If you need to generate a testNG report, you also need to download the test-result.xsi file.

4.3 Beautified running results report

Hope it helps everyone~

Finally, I would like to thank everyone who has read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!

Software testing interview document

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Java Skill TreeHomepageOverview 139065 people are learning the system