Detailed steps for practicing interface testing

Recently, I learned Python language, re-learned Java, js, html language, CSS, linux, and a bunch of testing tools; alas ~

I made up a lot of lessons during the contact interface testing process.

Finally, I understand the fundamentals of interface testing;

I am a pragmatist, so I basically don’t have a big idea about things that are not useful in reality;

The following are the unified steps for interface testing. In fact, it gives us an overall concept of interface testing. If we want to do or learn interface testing, we should start from those places. That is to say, after searching for interface testing on Baidu for a long time, , I still have no idea, so what should I do? So the following steps are the steps you need to take apart the interface test to understand;

For example, in the first step, after Baidu, we need to study what resful is and how to add, delete, modify and check;

These steps can be broken down and practiced repeatedly. Once these steps are broken down and practiced, your interface testing will be thorough and all interface tests will be eliminated.

Interface testing: Http class, webservice class are actually similar

It’s okay to find a project of your own, one where no one has done interface testing, so that you can figure out how to test it yourself instead of relying on other people’s thoughts and ideas. . . The most important thing is that the journey from having no ideas to having ideas is not long. As long as you start doing this, believe me, you will soon find that you are indeed very smart~~~~~~

Disclaimer: The reason why I can get started with these things is mainly due to the interface testing concept of the ethanol master, the generous teachings of my friend Feng xx, and various scattered ideas on the Internet;

The first step: first understand what you want to test? The essence is to add, delete, modify and check. (scientific name is resful);

Step 2: First use the tools recommended on the Internet to get a feel for it (for example: postman, for example: SoapUI)

Step 3: How to use get, post, put, delete, such as passing parameters (such as json string), and how to view the results (these do require you to have some technical foundation, such as ports, return values, and encoding types)

Step 4: So, now that we have learned the language, let’s use it (be sure to take a look at the written interface example, otherwise, you don’t know what package or function of this language to use to help us) Get the data of URL, etc...)

Step 5: Then let’s add the framework (Unittest). Compare it with your old version and the self-created version. You will feel ~~ and then understand why you use the framework. Practice is indeed an interesting thing;

Step 6: Put your parameters into the database, or excel, etc. to achieve data drive; let’s do it

Step 7: Optimize your code and refactor over and over again. You should be on your way to becoming a python master.

Step 8 : Of course, if you know Java but don’t know how to use it to write interface tests, then turn these use cases into Java.

Step 9: Then what else can you do? There are many more. Think: If your current interface only tests interface A, can interface B be tested? For example, if C calls A interface, then C is an interface? Really~~ Can you tell it apart? Make it clear. If it is not an interface, or what it is, can it be tested? How to test it?

Step 10 : Make a fake interface (Moco) yourself: it is best to integrate it with your current project, such as what is being developed (communicate with the development); test it yourself

Step 11: Write an interface yourself (you can first draw a picture of the previously developed interface, but you also have to draw it, you must draw it, who said you are a tester, know yourself and know the enemy~), simple first, It's complicated at the end, the main thing is to understand the principles clearly. You don't do development anyway (of course if you want to do development, then do development, don't waste time here); test it yourself

Step 12: Start to test the second interface. This time you can just start from step 6 (beautiful code is not made in a day)

If you are very detailed, I think that three interfaces should be enough. In the end, you must remember to use your knowledge to sell it in the market; technology is the primary productive force~~

In fact, with this foundation, it should not be difficult to overturn other aspects of automation.

 The first version of unittest framework source code
 

 1 # Lawsuit_interface_unittest.py
 2 # coding:utf-8
 3 
 4 import json
 5 import unittest
 6 from suds.client import Client
 7 
 8 
 9 class Lawsuit_interface_testing(unittest.TestCase):
10 
11     def setUp(self):
12         self.url = "http://.....:8080/sys/webservice/sysNotifyTodoWebService?wsdl"
13         self.client = Client(self.url) #
14 
15     def tearDown(self):
16         pass
17 
18     def test_getTodo(self):
19 
20         notify_TodoGetContext = self.client.factory.create(
21             'notifyTodoGetContext')
22         notify_TodoGetContext.otherCond = ""
23         notify_TodoGetContext.pageNo = 1
24         notify_TodoGetContext.rowSize = 3
25         notify_TodoGetContext.targets = json.dumps(
26             {"LoginName": "xiaoming"})
27         notify_TodoGetContext.type = 1
28         notify_TodoAppResult = self.client.service.getTodo(
29             notify_TodoGetContext)
30         returnState = notify_TodoAppResult.returnState
31         self.assertEqual(returnState, 2)
32 
33     def test_sendTodo(self):
34 
35         notify_TodoSendContext = self.client.factory.create(
36             'notifyTodoSendContext')
37         notify_TodoSendContext.appName = "Lawsuit"
38         notify_TodoSendContext.createTime = "2015-11-27 15:32:39"
39         notify_TodoSendContext.key = ''
40         notify_TodoSendContext.link = 'http://wwww.baidu.com'
41         notify_TodoSendContext.subject = 'Lawsuit_testing'
42         notify_TodoSendContext.modelId = '123456789'
43         notify_TodoSendContext.modelName = "Lawsuit"
44         notify_TodoSendContext.targets = json.dumps(
45             {"LoginName": "xiaoming"})
46         notify_TodoSendContext.type = 1
47         notify_TodoAppResult = self.client.service.sendTodo(
48             notify_TodoSendContext)
49         returnState = notify_TodoAppResult.returnState
50         self.assertEqual(returnState, 2)
51 
52     def test_deleteTodo(self):
53 
54         notify_TodoRemoveContext = self.client.factory.create(
55             'notifyTodoRemoveContext')
56         notify_TodoRemoveContext.appName = "Lawsuit"
57         notify_TodoRemoveContext.modelId = '123456789'
58         notify_TodoRemoveContext.key = ''
59         notify_TodoRemoveContext.modelName = "Lawsuit"
60         notify_TodoRemoveContext.optType = 1
61         notify_TodoRemoveContext.targets = json.dumps(
62             {"LoginName": "xiaoming"})
63         notify_TodoAppResult = self.client.service.deleteTodo(
64             notify_TodoRemoveContext)
65         returnState = notify_TodoAppResult.returnState
66         self.assertEqual(returnState, 2)
67 
68     def test_setTodoDone(self):
69 
70         notify_TodoRemoveContext = self.client.factory.create(
71             'notifyTodoRemoveContext')
72         notify_TodoRemoveContext.appName = "Lawsuit"
73         notify_TodoRemoveContext.modelId = '123456789'
74         notify_TodoRemoveContext.key = ''
75         notify_TodoRemoveContext.modelName = "Lawsuit_testing"
76         notify_TodoRemoveContext.optType = 1
77         notify_TodoRemoveContext.targets = json.dumps(
78             {"LoginName": "xiaoming"})
79         notify_TodoAppResult = self.client.service.setTodoDone(
80             notify_TodoRemoveContext)
81         returnState = notify_TodoAppResult.returnState
82         self.assertEqual(returnState, 2)
83 
84 
85 if __name__ == '__main__':
86     unittest.main()

 The second version is driven by excel data

 1 # Lawsuit_interface_unittest_excel_v1.1.py
  2 # coding:utf-8
  3 
  4 import unittest
  5 import json
  6 import xlrd
  7 from suds.client import Client
  8 import time
  9 import sys
 10 
 11 
 12 class Lawsuit_interface_testing(unittest.TestCase):
 13 
 14     def setUp(self):
 15         self.url ='http:// xx?wsdl'
 16         self.client = Client(self.url)
 17         self.xlsfile = r'lawsuit_casedata.xlsx'
 18         self.excel_data(self.xlsfile)
 19 
 20     def tearDown(self):
 21         pass
 22 
 23     def test_getToDO(self):
 24 
 25         self.Cannot_find_file(self.xlsfile)
 26 
 27         notify_TodoGetContext = self.client.factory.create(
 28             'notifyTodoGetContext')
 29         notify_TodoGetContext.pageNo = self.pageNo_value
 30         notify_TodoGetContext.rowSize = self.rowSize_value
 31         # another way to json
 32         # notify_TodoGetContext.targets = "{ \"LoginName\": \"xiaoming\" }"
 33         notify_TodoGetContext.targets = self.targets_value
 34         notify_TodoGetContext.type = self.ptype_value
 35 
 36         notify_TodoAppResult = self.client.service.getTodo(
 37             notify_TodoGetContext)
 38         returnState = notify_TodoAppResult.returnState
 39 
 40         print returnState
 41         self.assertEqual(returnState, 2)
 42 
 43     def test_sendTodo(self):
 44         self.Cannot_find_file(self.xlsfile)
 45 
 46         notify_TodoSendContext = self.client.factory.create(
 47             'notifyTodoSendContext')
 48         notify_TodoSendContext.appName = self.appName_value
 49         notify_TodoSendContext.createTime = self.creatime_value
 50         # notify_TodoSendContext.key = ''
 51         notify_TodoSendContext.link = self.link_value
 52         notify_TodoSendContext.subject = self.subject_value
 53         notify_TodoSendContext.modelId = self.modelId_value
 54         notify_TodoSendContext.modelName = self.modelName_value
 55         notify_TodoSendContext.targets = self.targets_value
 56         notify_TodoSendContext.type = self.ptype_value
 57         notify_TodoAppResult = self.client.service.sendTodo(
 58             notify_TodoSendContext)
 59         returnState = notify_TodoAppResult.returnState
 60         self.assertEqual(returnState, 2)
 61 
 62     def test_deleteTodo(self):
 63         self.Cannot_find_file(self.xlsfile)
 64 
 65         notify_TodoRemoveContext = self.client.factory.create(
 66             'notifyTodoRemoveContext')
 67         notify_TodoRemoveContext.appName = self.appName_value
 68         notify_TodoRemoveContext.modelId = self.modelId_value
 69         # notify_TodoRemoveContext.key = ''
 70         notify_TodoRemoveContext.modelName = self.modelName_value
 71         notify_TodoRemoveContext.optType = self.optType_value
 72         notify_TodoRemoveContext.targets = self.targets_value
 73         notify_TodoAppResult = self.client.service.deleteTodo(
 74             notify_TodoRemoveContext)
 75         returnState = notify_TodoAppResult.returnState
 76         self.assertEqual(returnState, 2)
 77 
 78     def test_setTodoDone(self):
 79         self.Cannot_find_file(self.xlsfile)
 80 
 81         notify_TodoRemoveContext = self.client.factory.create(
 82             'notifyTodoRemoveContext')
 83         notify_TodoRemoveContext.appName = self.appName_value
 84         notify_TodoRemoveContext.modelId = self.modelId_value
 85         # notify_TodoRemoveContext.key = ''
 86         notify_TodoRemoveContext.modelName = self.modelName_value
 87         notify_TodoRemoveContext.optType = self.optType_value
 88         notify_TodoRemoveContext.targets = self.targets_value
 89         notify_TodoAppResult = self.client.service.setTodoDone(
 90             notify_TodoRemoveContext)
 91         returnState = notify_TodoAppResult.returnState
 92         self.assertEqual(returnState, 2)
 93 
 94     def excel_data(self, xlsfile):
 95 
 96         self.Cannot_find_file(self.xlsfile)
 97         book = xlrd.open_workbook(xlsfile)
 98         api_sheet = book.sheet_by_index(0)
 99         nrows = api_sheet.nrows
100         for i in range(1, nrows):
101             caseID = api_sheet.cell(i, 0)
102             appName = api_sheet.cell(i, 1)
103             creatime = time.strftime(
104                 time.strftime('%Y-%m-%d %X', time.localtime(time.time())))
105             link = api_sheet.cell(i, 3)
106             subject = api_sheet.cell(i, 4)
107             modelId = api_sheet.cell(i, 5)
108             modelName = api_sheet.cell(i, 6)
109             targets = api_sheet.cell(i, 7)
110             ptype = api_sheet.cell(i, 8)
111             pageNo = api_sheet.cell(i, 9)
112             rowSize = api_sheet.cell(i, 10)
113             optType = api_sheet.cell(i, 11)
114             # returnstatue = api_sheet.cell(i, 12)
115             # message = api_sheet.cell(i, 13)
116             if api_sheet.cell(i, 0).ctype != 0:
117                 # caseID_value=str(int(caseID.value))
118                 self.appName_value = appName.value
119                 self.creatime_value=creatime
120                 self.link_value = link.value
121                 self.subject_value = subject.value
122                 self.modelId_value = modelId.value
123                 self.modelName_value = modelName.value
124                 # print type(targets)
125                 self.targets_value = targets.value
126                 # print type(targets.value)
127                 self.ptype_value = int(ptype.value)
128                 self.pageNo_value = int(pageNo.value)
129                 self.rowSize_value = int(rowSize.value)
130                 self.optType_value = int(optType.value)
131 
132                 # returnstatue_value=returnstatue.value
133                 # message_value=message.value
134             else:
135                 return 0
136             #    data1=
137 
138         # return data1
139 
140     # exception
141 
142     def Cannot_find_file(self, xlsfile):
143         try:
144             foo = open(self.xlsfile)
145         except EnvironmentError as err:
146             print "Unable to open file:{}".format(err)
147             sys.exit(1)
148 
149 
150 if __name__ == '__main__':
151     unittest.main()

Thank you to everyone who reads my article carefully. There is always a courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly:

 These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you! Anyone in need Partners can click on the small card below to receive it

 

Guess you like

Origin blog.csdn.net/okcross0/article/details/133134546