CS代考 Basic Testing – assert and test driver

Basic Testing – assert and test driver
The University of 1

assert statement – Syntax:

Copyright By PowCoder代写 加微信 powcoder

– Meaning:
– IfisFalse,raiseAssertionErrorwiththe
– AssertionError
• An exception that is raised by the assert statement fails.
• https://docs.python.org/3/library/exceptions.html#AssertionError
– Go to Ed Lesson
– Review the codes in demo.py. What do you notice about both code
– Predicttheoutputoftheprogram.Runtheprogramtocheckyouranswer.
assert ,
The University of 2

assert statement – Review the codes in
integer.py.
– Isthefunctionbehaving
according to specification?
– Determinetheoutputofthe program if the function:
– Satisfies the requirements? – Does not satisfy the
requirements?
– Run the program to check your answer.
The University of 3

Manual Testing: The problem
– Many different test cases can be produced to thoroughly test a program.
– Every time you fix something, you should re-run all your previous tests
– Regression testing: Running ALL your tests again whenever you make a significant change to your code to make sure you haven’t broken code that used to work.
– Solution: Automated Testing
– Allows testing to be repeated as many times until the problem is fixed.
– Reduces human error in executing the test. – Reportoftestingresults.
– Ideally, test codes should be in a separate file to minimize risk of modifying the test object during test development. This file is called the test driver.
The University of 4

Basics of Programming
– All procedural programming languages have loops, conditionals and functions. These basic constructs can be used to solve any problem.
– The syntax may be different for other languages but the principles are the same.
– Why should we use functions when we can write codes without functions?
– Code re-usability
– Reduce errors
– Independent testing – unit testing
The University of 5

Functions and Modules
– Module contains functions that are available to be use by other programs.
– Client is a program that makes use of a function in a module.
– import statement at the top of the program. • Syntax: import
– Qualify function calls to the module using dot operator
• Syntax: .
– The module must be in the same directory as the client.
The University of 6

Test Driver
– Importthemodulethatcontainsthefunctiontobetest.
– Define a function for each test case.
– Callthefunctionstorunthetestcasesaccordingly.
– Can you tell which test case passes and fails?
– Did you actually run all the tests?
– Go to Ed Lesson and run test_driver.py.
The University of 7

Summary – PIAT for Testing
– Determine the purpose of testing.
– Write test cases – positive, negative and edge cases.
– Implement the test cases.
– Importthemodulethatcontainsthefunctiontobetest. – Defineafunctionforeachtestcase.
• Assert statements to check the expected output with the actual output
• Save or display result of testing.
– Callthefunctionstorunthetestcasesaccordingly.
The University of 8

Practice: Testing – search function
– Writeassertstatementsforeachofthetestcasesinsidethe main() body. Is this a good testing practice?
– Writetestfunctionstoimplementeachtestcase.Runthetests. Does the program tell you whether the test cases pass or fail?
The University of 9

Reading This Week
– Chapter2.2.Unittesting.Sedgewick,R.,Wayne,K.,& Dondero, R. (2015). Introduction to programming in Python: An interdisciplinary approach. Addison- .
– Chapter1,2,4.Sale.(2014).TestingPython:ApplyingUnit Testing, TDD, BDD and Acceptance Testing. Wiley. https://sydney.primo.exlibrisgroup.com/permalink/61USYD_IN ST/1c0ug48/alma991004562199705106
The University of 10

Supplementary: Software and Accidents
– Turning90degreesinairandself-destructing. – https://youtu.be/gp_D8r-2hwk
– NHSITblunder
– Wrong prescriptions for 300, 000 heart patients
– https://www.dailymail.co.uk/health/article-3585149/Up-300-000- heart-patients-given-wrong-drugs-advice-major-NHS-blunder.html
– UberSelf-DrivingCar
– Softwaredidnotrecognizepedestrian.SUVdidnotneedtostop!
– Driverchargeforbeing‘visuallydistracted’.Pedestriankilled.
– https://www.npr.org/2019/11/07/777438412/feds-say-self-driving- uber-suv-did-not-recognize-jaywalking-pedestrian-in-fatal-
The University of 11

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com