Concept: verify whether the software meets user requirements
Difference between testing and development
Commissioning and testing
Test: check whether the software realizes the functions that should be realized;
Debugging: the programmer checks whether the software realizes the function that the code should realize.
Testing: testers and developers
Development: debug only in the development phase
Testing: throughout the life cycle of software development
Test: the technical requirements are wide, but the depth is lower. Require to use various tools and understand some languages
Development: specific technical requirements and high depth
Why software testing
- Compressive capacity
Why not develop and test
Learned development knowledge = = > learned software testing = = > interested = = > learned development to test better
Concept: permissions and skills required to meet user needs or formal documents
Testers are involved in testing during the requirements phase
User requirements: what do users want to do, eat braised meat
Software requirements: what do you need to do to make braised meat? Buy meat, seasoning, etc
Concept: if and only if the specification exists and is reasonable, the function and requirement specification of the software do not meet the specification, which indicates that it is a software error;
When the software specification does not exist, the user's demand is reasonable, and the software function is inconsistent with the demand specification, it indicates that the software is wrong.
In other words, no matter whether the specification exists or not, as long as the user's requirements are reasonable, but the software function does not meet the requirements specification, it is a bug
Concept: a set of sets initiated to the test system; Including: test environment, test steps, test data, expected results, title, test function module, priority, importance, etc.
Iterative and incremental model
Roles: Product Manager (PO), project manager (SM), R & D team (ST)
Product release meeting = = > iteration planning meeting = = > daily station meeting during development = = > demonstration meeting = = > review meeting
Software test model
When did the tester get involved in the test?
- W model, intervene in demand analysis;
Disadvantages: serial execution, does not support agile development;
V model, intervene after coding.
Disadvantages: unable to intervene in the requirements phase
Software testing process (software testing life cycle)
Requirement analysis = = > test plan = = > test design / development = = > test execution = = > Test Report
How to describe a BUG
Test version (system version) + test environment (browser version, etc.) + test steps + test data + expected results + actual results + attachments (error screenshots and error logs)
When a new function of the system goes online and it is found that the user crashes when using a function and cannot be repaired, how can the tester deal with it?
- Fallback Version (system stable version)
- Pay close attention to the implementation and repair of the problem
BUG life cycle
After the developer fixes a BUG, the BUG is still found during the test. What are the possible reasons
- Development inspection, whether to submit new code after repairing the code;
- The tester did not re extract the code of the test environment;
- It is true that the developer did not modify it successfully.
How to deal with conflicts between testers and developers due to bugs?
- Check whether the BUG description is clear and correct;
- Convince developers from the perspective of users;
- The ranking of bugs is reasonable and justified. Don't exaggerate;
- Testers constantly improve their level and can find bugs and their causes, as well as solutions;
- Hold a tripartite meeting (product manager, developer and tester) to discuss BUG solutions.
Design test case basis
Design test cases according to requirements
Analyze requirements, refine requirements, extract function points / test points from requirements, and then design test cases with specific methods of design and testing;
Black box test design test case method
Equivalence class, boundary value, cause and effect diagram, scenario design method, wrong guess method, orthogonal method
Test case design method
Concept: divide the input (output is considered only in special cases) into several equivalent classes, and select a test case from each equivalent class for testing. If the test case passes, it means that the equivalent class represented by the test case passes the test.
Usage: there are too many test cases to be exhaustive
Valid equivalence class: enter meaningful input for this function (enter legal user name)
Invalid equivalence class: meaningless input for this function (illegal user name input)
Concept: design test cases according to the boundary of input
Cause and effect diagram
Usage: there are multiple conditions for input, and different combinations of inputs correspond to different inputs
Logical relation: and or non identity
Use steps: analyze possible inputs and outputs = = > find out the preference between inputs and outputs = = > draw the cause and effect diagram = = > draw the cause and effect diagram into the judgment table = = > write test cases according to the judgment table
Analyze possible inputs and outputs
Input: order submission, amount greater than 300, with red envelope
Output: with or without discount
Find out the preference between input and output
Draw a cause and effect diagram
Draw a decision table: there are 3 inputs and 2 outputs, and the corresponding number of columns 2 ^ 3 = 8
Concept: combine isolated function points in the system according to certain logic to form a scenario / business, and test the scenario
First, determine each function point in the scene, and determine the possible input and different output of the function point
Concept: the first mock exam is based on the intuition, experience and knowledge of the tester, and then the design of test cases is designed.
Concept: study a test case design method of multi factors (different inputs) and multi levels (different inputs and different values). According to the orthogonality, select the optimal input combination for the test, analyze the test results, and use the results to measure the overall test results
How to test TCP and UDP protocols?
The functions and characteristics of TCP and UDP are analyzed respectively
Function: transmit data
Features: reliable (whether ACK is received or not), three handshakes (test according to different signals sent each time of the three handshakes), data flow, four waves, etc
Function: transmit data
Features: datagram, unreliable, fast.
Divided by development stage
Classification: Junit unit test framework (white box), unittest unit test framework (black box)
Basis: detailed design documents
Concept: integration test, also known as joint test (joint commissioning) and assembly test, assembles program modules with appropriate integration strategies to test the correctness of system interfaces and integrated functions. The main purpose of integration is to check whether the interface between software units is correct.
Test method: white box test
The object of smoke test is each newly compiled software version that needs formal test. The purpose is to confirm that the basic function of the software is normal and can carry out subsequent formal test, that is, system test. The executor of the smoke test is the version compiler.
The software system is regarded as the test of a system. It includes testing the function, performance and the software and hardware environment in which the software runs. Most of the time is in the system test execution stage, including regression test and smoke test.
Test method: black box test
Concept: check whether the newly introduced code has an impact on the old functions
Acceptance testing is the last test operation before deploying software. It is the last stage of technical testing, also known as delivery testing. The purpose of acceptance test is to ensure that the software is ready. According to the project contract, assignment and acceptance basis documents agreed by both parties, the software system meets the original requirements
By implementation organization
Non testing, non developer testing
Real users test at any time and place (internal test)
Divided by manual
Manual testing is that people enter use cases one by one and then observe the results. Corresponding to machine testing, it is a relatively primitive but necessary one.
Advantages: automation cannot replace exploratory testing and testing of divergent thinking results.
Disadvantages: slow execution efficiency, large quantity and easy to make mistakes.
Write automated scripts to test the designed test cases
Automated testing cannot replace manual testing
Do not run the code, analyze the code for testing
Run the code, check the similarities and differences between the expected results and the actual results, and analyze the differences, operation efficiency, correctness, etc
Divided by whether to view code
Black box test (unittest)
Regard the software as a black box, do not care about the logical structure implementation of the internal code of the software, only care about the input and output
White box test (Junit)
Test whether the internal logic and structure of the program have realized the corresponding functions
Test methods: statement coverage, logic coverage (decision coverage / condition coverage / decision combination / condition combination / decision and condition combination), path coverage (if / else / try / catch), loop coverage (for / while)
Divided by test object
Concept: it is the function defined by the tester to run the modules of the system in series, simulate the actual workflow of the real user, and meet the user's needs
- Layout layout
- Font size, thickness, etc
- Is the picture clear
- Page controls (buttons, scroll bars, checkboxes, etc.)
Fault Tolerance Testing
Concept: when the system has an exception due to external reasons, it can handle it by itself, do not show the exception directly to the user, and give the user a friendly prompt
Ease of use is the concentrated embodiment of the adaptability, functionality and effectiveness of interaction. Ease of use belongs to the category of ergonomics. Ergonomics is a discipline that designs everyday things as easy-to-use and practical
Compatibility mainly refers to whether the software can operate well, whether it will have an impact, whether the software and hardware can work efficiently, and whether it will affect the system crash.
In the actual testing, the most common is the testing of user files, such as manuals, etc. some companies will also test the requirements documents to ensure the quality of the requirements documents.
Check whether the system meets the performance specified in the requirements specification.
Security testing is a relatively independent field, which needs more professional knowledge. For example, web security testing needs to be familiar with various network protocols
TCP\HTTP, firewall, CDN, familiar with vulnerabilities of various operating systems, familiar with routers, etc. in terms of software, familiar with various attack methods, such as SQL injection, Xss, etc.
Memory leak test
The user allocated memory space and did not recycle it, resulting in more and more memory occupied.
Automated testing (selenium)
webdriver basic usage
How to locate elements
# Locate with id Input box id = kw Send Zhang Jiawen to the input box driver.find_element_by_id("kw").send_keys("Zhang Jiawen") # Baidu click driver.find_element_by_id("su").click() # Locate with name driver.find_element_by_name("wd").send_keys("Zhang Jiawen") driver.find_element_by_id("su").click() # class name positioning driver.find_element_by_class_name("s_ipt").send_keys("Zhang Jiawen") driver.find_element_by_class_name("bg s_btn").click() # Link textpositioning driver.find_element_by_link_text("Post Bar").click() # partial positioning driver.find_element_by_partial_link_text("bar").click() # tag name location driver.find_element_by_tag_name("") # xpath positioning driver.find_element_by_xpath("//*[@ id ='kw '] ". Send_keys (" Zhang Jiawen ") driver.find_element_by_xpath("//*[@id='su']").click() # css selector driver.find_element_by_css_selector("#kw").send_keys(" Zhang Jiawen ") driver.find_element_by_css_selector("#su").click()
similarities and differences
Same: the same as time.wait(10), if neither of them finds the next required element after waiting for 10s, an exception will be thrown
Different: time.sleep() is a fixed wait, while driver. Implicitly_wait() is to wait until it is found, rather than wait
Get browser title and URL
# Get title driver.title # Get URL driver.current_url
Browser window size
# Set browser window driver.set_window_size(600,1000) # Browser maximization driver.maximize_window()
Forward and backward
# forward driver.forward() # back off driver.back()
# Package required from selenium.webdriver.common.keys import Keys # usage driver.find_element_by_name("username").send_keys(Keys.CONTROL,'a') driver.find_element_by_name("username").send_keys(Keys.CONTROL,'c') driver.find_element_by_name("password").send_keys(Keys.ENTER)
# Package required from selenium.webdriver.common.action_chains import ActionChains # Right click name = driver.find_element_by_id("su") ActionChains(driver).context_click(name).perform() # double-click ActionChains(driver).double_click(name1).perform()
Multiple selection (CheckBox)
for input in inputs: if input.get_attribute('type') == 'checkbox': input.click()
Drop down box
# Positioning through css selector driver.find_element_by_css_selector("#ShippingMethod > option:nth-child(5)").click() # Array subscript options.click()
From the default frame to f2, you need to go to f1 first;
From f2 to the default frame, you also need to go to f1 first;
from selenium import webdriver import unittest import time import os # Function of unittest.TestCase: the class Unit inherits unittest.TestCase class Unit(unittest.TestCase): def setUp(self): print("run setUp") self.driver = webdriver.Chrome() self.url = "https://www.baidu.com/" self.driver.maximize_window() def tearDown(self): print("run tearDown") self.driver.quit() if __name__=="__main__": unittest.main()
from Test import unitDemo from Test import unitDemo1 import unittest def createsuite(): # addTest loads one test case of a test script into the test suite at a time suite = unittest.TestSuite() suite.addTest(unitDemo.Unit("test_Abaidu")) suite.addTest(unitDemo.Unit("test_abaidu")) suite.addTest(unitDemo1.Unit("test_cbaidu")) suite.addTest(unitDemo1.Unit("test_Dbaidu")) def createsuite1(): # Load all test cases in a test script into the suite suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(unitDemo.Unit)) suite.addTest(unittest.makeSuite(unitDemo1.Unit)) return suite def createsuite2(): # TestLoader # Load all test cases in a test script into the suite suite1 = unittest.TestLoader().loadTestsFromTestCase(unitDemo.Unit) suite2 = unittest.TestLoader().loadTestsFromTestCase(unitDemo1.Unit) suite = unittest.TestSuite([suite1, suite2]) return suite def createsutie3(): # Add all test scripts named in some form in a folder to the test suite discover = unittest.defaultTestLoader.discover("../Test", pattern="unitDemo*.py",top_level_dir=None) return discover if __name__=="__main__": suite = createsuite1() runner = unittest.TextTestRunner(verbosity=2) runner.run(suite)
Ignore test case execution
@unittest.skip("skipping") # Note: ignore test case execution def test_abaidu(self): driver = self.driver url = "https://www.baidu.com/" self.driver.get(url) driver.find_element_by_id("kw").send_keys("pighead") driver.find_element_by_id("su").click() time.sleep(3) title = driver.title try: self.assertEqual("pighead_use Baidu Search", title, msg="Unequal") except: self.saveScreenShot(self,driver,"pighead.png") time.sleep(3)
Function: judge whether the expected results are consistent with the actual results
# Assert def test_abaidu(self): driver = self.driver url = "https://www.baidu.com/" self.driver.get(url) driver.find_element_by_id("kw").send_keys("pighead") driver.find_element_by_id("su").click() time.sleep(3) title = driver.title try: self.assertEqual("pighead_use Baidu Search", title, msg="Unequal") except: self.saveScreenShot(self,driver,"pighead.png") time.sleep(3)
# Operation sequence 0-9 A-Z a-z # screenshot def test_Abaidu(self): driver = self.driver url = self.url driver.get(url) driver.find_element_by_id("kw").send_keys("It's you") driver.find_element_by_id("su").click() time.sleep(3) title = driver.title print(title) try: self.assertEqual("123 It's you_use Baidu Search",title,msg="Unequal") except: self.saveScreenShot(driver,"It's you.png") time.sleep(3)
Function: output all results to HTML report
import os import sys import time import unittest import HTMLTestRunner def createsuite(): discovers = unittest.defaultTestLoader.discover("../Test", pattern="unitDemo*.py", top_level_dir=None) print(discovers) return discovers if __name__=="__main__": #1. Create a folder # Current path curpath = sys.path # sys.path is an array of path collections print(sys.path) print(sys.path) # When the resultreport folder under the current path does not exist, create one if not os.path.exists(curpath+'/resultreport'): os.makedirs(curpath+'/resultreport') # 2. Solve the problem of duplicate naming now = time.strftime("%Y-%m-%d-%H %M %S", time.localtime(time.time())) print(time.time()) print(time.localtime(time.time())) # The file name is the path plus the name of the file # Prepare HTML report output file filename = curpath + '/resultreport/'+ now + 'resultreport.html' # Open the HTML file and wb write it with open(filename, 'wb') as fp: # The parameters in parentheses are the parameters in the HTML report runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u"Test report", description=u"Use case execution", verbosity=2) suite = createsuite() runner.run(suite)
Installation kit: pip install ddt
from selenium import webdriver import unittest import time from ddt import ddt, unpack, file_data, data import sys, csv def getTxt(file_name): # ([cat, cat Baidu search], [dog, dog Baidu search], [pig, pig Baidu search]) rows =  path = sys.path with open(path + '/data/' + file_name, 'rt',encoding='utf-8') as f: readers = csv.reader(f, delimiter=',', quotechar='|') next(readers, None) for row in readers: temprows= # Cat, cat_ Baidu search for i in row: temprows.append(i) rows.append(temprows) return rows def getCsv(): # Read csv file values =  with open('data/test_help_json.csv', encoding='utf-8') as f: f_scv = csv.reader(f) next(f_scv) for i in f_scv: values.append(i) return values @ddt class Baidu(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.implicitly_wait(30) self.base_url = "http://www.baidu.com/" self.driver.maximize_window() self.verificationErrors= self.accept_next_alert=True def tearDown(self): self.driver.quit() self.assertEqual(,self.verificationErrors) # json data # Get one at a time @unittest.skip("skipping") @file_data('data/test_baidu_data.json') def test_baidu1(self, value): driver = self.driver driver.get(self.base_url+"/") driver.maximize_window() driver.find_element_by_id("kw").clear() driver.find_element_by_id("kw").send_keys(value) driver.find_element_by_id("su").click() time.sleep(3) @unittest.skip("skipping") @data("cat","dog","pig","pig") # Use data to put data directly def test_baidu2(self, value): driver = self.driver driver.get(self.base_url+"/") driver.find_element_by_id("kw").clear() driver.find_element_by_id("kw").send_keys(value) driver.find_element_by_id("su").click() self.assertEqual(value,driver.title,msg="Non conformity") time.sleep(3) @data(['pig',u'pig_Baidu Encyclopedia'],['pig',u'pig_Baidu Encyclopedia']) @unpack # unpack is required to use two parameters def test_baidu3(self, value, expected_value): driver = self.driver driver.get(self.base_url + "/") driver.find_element_by_id("kw").clear() driver.find_element_by_id("kw").send_keys(value) driver.find_element_by_id("su").click() time.sleep(3) self.assertEqual(expected_value, driver.title, msg="Not as expected") print(expected_value) print(driver.title) time.sleep(3) # Read txt text @data(*getTxt('test_helpddt.txt')) @unpack def test_baidu4(self, value, expected_value): driver = self.driver driver.get(self.base_url + "/") driver.find_element_by_id("kw").clear() driver.find_element_by_id("kw").send_keys(value) driver.find_element_by_id("su").click() time.sleep(3) self.assertEqual(expected_value, driver.title, msg="Not as expected") print(expected_value) print(driver.title) time.sleep(3) # Read json file @data(*getCsv()) @unpack def test_baidu5(self,value,expected_value): driver = self.driver driver.get(self.base_url+"/") driver.find_element_by_id("kw").clear() driver.find_element_by_id("kw").send_keys(value) driver.find_element_by_id("su").click() self.assertEqual(value,expected_value,msg="Mismatch") time.sleep(3) if __name__=="__main__": unittest.main()