New version page

Toronto CSC 309H - Web Porgramming - Web Testing

Upgrade to remove ads
Upgrade to remove ads
Unformatted text preview:

CSC309: Web ProgrammingGreg Wilson 1      Remember testing?It’s ironic: distributed applications are harder to debug, but we test them lessStandard web applications are not harder to test than other programsProvided you design them for testability in the first placeThe things you do to make them testable are things you should be doing anyway  !" Legacy code (n.): source code that relates to a no-longer supported computer systemOften used as an insult, meaning “a mess you’d wish on your worst enemy”Feathers’ definition: “legacy code is code that doesn’t have unit tests”Without comprehensive unit tests, you can never be sure that your changes haven’t broken something#$  How do you test this?HTTP requestHTMLApache Python CGIPostgreSQLFilesystemCSC309: Web ProgrammingGreg Wilson 2%&   '(")(Accept the system as givenSend HTTP, parse HTMLFaithfulLots of workAnd remember, screen scraping is fragileHTTP requestHTMLApache Python CGIPostgreSQLFilesystem*+ "" ,Do regression testing to make sure that we haven’t broken anything that used to workSo:Record a working system (HTTP in, text out)Replay the HTTP, and diff the resultWinRunner is the gold standard for desktop appsMaxQ (maxq.tigris.org)Allows non-programmers to create and run testsBut you have to have a nearly-working system……and it’s still screen-scraping-./!$$  0Don’t look at HTML directlyInstead, insert markers and look for thoseMuch less likely to change over time<p> User ID:<em class=“test” role=“uid”>GVW</em></p>Going to use CSS to style the page anywayNot checking everything……but giving yourself more time to check the things that require human eyeballs12 !$$  HTTP requestXMLApache Python CGIPostgreSQLFilesystemCSC309: Web ProgrammingGreg Wilson 334,$   How about getting rid of the web server?Run the CGI ourselvesTell it to produce XML (or plain text) rather than HTMLMakes debugging easierBut testing even less faithfulTest CodeFakeCGI Python CGIPostgreSQLFilesystem2 4,$   "All" we need is our own cgi.FieldStorageAnd os.environAnd sys.stdin and sys.stdoutDesign for testabilityCode to interfaces, not implementations                 5 ' Database is persistent storageThat’s its whole purposeBut tests are supposed to be independentIn theory, create a new database for each In practice, just wipe and re-fill the tablesIf tests are slow, programmers won’t run them2 ' “If tests are slow” covers a lot of sinsHow long does it take developers to set up?Install the software the first time?Reinstall/reconfigure for testing?Will it interrupt real service?Will it impact other developers?SelectAccess: could take two full days to install and configureWhich was eight days less than the competitionCSC309: Web ProgrammingGreg Wilson 42 ' Solution: change what you’re testingSQLite and HSQLDB are much smaller than PostgreSQLAnd both can store database in memoryUseless for real work, but great for testingDesign for testing:Abstract away the details of external packages A good idea anywayRun developer tests using replacementsStill do final tests with real system, of course#5,)6 If no replacement is available, build a mock objectBehaves like a limited version of the real thingE.g., when asked for contents of a file, hands back the path, reversedOnly works if you have a clean interface between your application and the subsystemBut you should anyway/5     Much simpler to (re)install and (re)initializeAnd much less likely to mess up production systemAs faithful as you make itWeeding out the easy problems gives developers more time to look at the hard onesTest CodeFakeCGI Python CGISQLite-MMockFS*'/ $ Goal is to produce something that can:Be run from the command line, so that its output can be compared to saved output (testing via Makefile)Be called inside unittest (Python’s equivalent of JUnit) as part of a larger test suiteWould like to avoid creating temporary filesMay need to pass command-line parameters to the thing being testedCSC309: Web ProgrammingGreg Wilson 5-/!'  cgi, requestType, url, headers = sys.argv[1:5]data = sys.stdin.read()if data:headers.append('Content-Length=%d' % len(data))os.putenv('REQUEST_METHOD', requestType)os.putenv('PATH_INFO', url)for h in headers:key, value = h.split('=', 1)os.putenv(key, value)childIn, childOut = os.popen2(cgi)childIn.write(data)childIn.close()result = childOut.read()while result:sys.stdout.write(result)result = childOut.read()1/    . if __name__ == '__main__':# Parse arguments.settings = parseArgs()# Convert headers.settings['headers'] = convertHeaders(settings['headers'])# Create server if required.if not settings['useExisting']:# Get rid of pre-existing .pyc (if any).if os.path.isfile('Nitinat.pyc'):os.remove('Nitinat.pyc')32     . # Create server.RequestHandler.RootDirectory = settings['root']childArgs = ['python', 'Nitinat.py','-h',


View Full Document
Download Web Porgramming - Web Testing
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Web Porgramming - Web Testing and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Web Porgramming - Web Testing 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?