Changes between Version 68 and Version 69 of DeveloperGuidelinesTesting


Ignore:
Timestamp:
01/24/09 14:01:16 (13 years ago)
Author:
Fran Boon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelinesTesting

    v68 v69  
    77[wiki:InstallationGuidelinesDeveloper#TestingSetup]
    88
    9 == Doc Tests ==
    10 Agile documentation which can be run using Web2Py's Admin UI.
    11 * e.g. http://127.0.0.1:8000/admin/default/test/sahana/default.py
    12 We have a module which uses [http://code.google.com/p/wsgi-intercept wsgi_intercept] & [http://cherrypy.org CherryPy]'s [http://cherrypy.org/browser/trunk/cherrypy/test/webtest.py WebTest]: {{{modules/s3_test.py}}}
     9== Functional Tests ==
     10Building the Right Code
     11
     12We have integrated [http://seleniumhq.org/projects/core Selenium Core] into {{{/static/selenium}}} so that Functional Tests can be run (via 'Test' menu option visible to Admins).
     13
     14Additional functions (e.g. Random) are added to:
     15{{{
     16/static/selenium/core/scripts/user-extensions.js
     17}}}
     18
     19!ToDo: create a HandleResults.py for storing results (to make visible to CI):
     20 * e.g. Convert this one from PHP: http://wiki.openqa.org/display/SEL/Integrating+Selenium+And+CruiseControl.Net
     21 * e.g. Extract from [http://jrandolph.com/selenium-plone/selenium-0.3rc2-plone.zip PloneTool]'s {{{FunctionalTestTool.py}}}
     22
     23Tests can be developed using [http://seleniumhq.org/projects/ide Selenium IDE], if desired.
     24
     25If desired they can be maintained in a Python format using [http://joker.linuxstuff.pl/documentation/make_selenium make_selenium.py]. HTML tests run by !TestRunner are in {{{/static/selenium/tests}}}. Python format tests are in {{{/static/selenium/src}}}. Convert between these using:
     26{{{
     27python make_selenium.py src tests
     28python make_selenium.py -p tests src
     29}}}
     30
    1331
    1432== Unit Tests ==
    1533Building the Code Right
    1634
    17 [http://seleniumhq.org/projects/remote-control Selenium RC]
     35[http://seleniumhq.org/projects/remote-control Selenium RC] is great due to ability to handle !JavaScript & also due to having an [http://seleniumhq.org/projects/ide IDE] for generating them (export as Python).[[BR]]
     36The IDE output needs to be [http://groups.google.com/group/web2py/msg/d8c9fd6008029f6b modified] to work with Web2Py.[[BR]]
     37NB Custom functions (e.g. for Random) cannot be shared with the Functional Tests (custom=JS) but the rest of the tests can be.[[BR]]
     38These tests are stored in {{{/tests}}}.[[BR]]
     39!ToDo:  Port the storeRandom function from JS to Python:
     40{{{
     41import random
     42print "test_%i@xxxxxxxx" % random.randint(1, 10000)
     43}}}
     44
     45[http://cherrypy.org CherryPy]'s [http://cherrypy.org/browser/trunk/cherrypy/test/webtest.py WebTest] is good for in-process testing.[[BR]]
     46These tests are stored in {{{/tests/webtest}}}.[[BR]]
     47NB These are a work-in-progress...need to enable access to Web2Py environment (db, etc) using:
     48{{{
     49from gluon.shell import exec_environment
     50env=exec_environment('the_model_file.py')
     51}}}
     52Or could write as a 'Controller' & call from CLI:
     53{{{
     54python web2py.py -S appname -M -R yourscript.py
     55}}}
     56
     57== Doc Tests ==
     58Agile documentation which can be run using Web2Py's Admin UI.
     59 * e.g. http://127.0.0.1:8000/admin/default/test/sahana/default.py
     60We have a module which uses [http://code.google.com/p/wsgi-intercept wsgi_intercept] & [http://cherrypy.org CherryPy]'s [http://cherrypy.org/browser/trunk/cherrypy/test/webtest.py WebTest]: {{{modules/s3_test.py}}} [[BR]]
     61This can be used from Controllers like:
     62{{{
     63def login():
     64    """ Login
     65    >>> from applications.sahana.modules.s3_test import WSGI_Test
     66    >>> test=WSGI_Test(db)
     67    >>> '200 OK' in test.getPage('/sahana/%s/login' % module)
     68    True
     69    >>> test.assertHeader("Content-Type", "text/html")
     70    >>> test.assertInBody('Login')
     71    """
     72}}}
     73This works fine,although if an assert fails then the UI gets stuck :/ [[BR]]
     74The 'db' access part isn't yet working.
     75
     76Note that Web2Py uses a big doctest at the end of each file: {{{def test_all()}}}
    1877
    1978== Continuous Integration ==
    20 We use the Trac-integrated Bitten to monitor code quality.
    21 
    22 == Functional Tests ==
    23 We have integrated [http://seleniumhq.org/projects/core Selenium Core] into /static/selenium so that Functional Tests can be run.
    24 Tests can be developed using [http://seleniumhq.org/projects/ide Selenium IDE], if desired.
    25 If desired they can be maintained in a Python format using
    26 
     79We are starting to use the Trac-integrated [http://bitten.edgewall.org Bitten] to monitor code quality.
     80{{{
     81<step id="lint" description="Run PyLint">
     82  <python:exec module="pylint.lint" output="pylint-report.txt" args="/var/www/trac/sahana3/bzr"/>
     83  <python:pylint file="pylint-report.txt" />
     84</step>
     85}}}
     86ImportError: Unable to find module for /var/www/trac/sahana3/bzr/modules/validators.py in /tmp/bittenA787wC/build_Trunk_1,
     87{{{
     88<step id="build" description="Compile to byte code">
     89  <python:distutils command="build"/>
     90</step>
     91}}}
     92distutils failed (512)[[BR]]
     93/usr/bin/python: can't open file '/tmp/bittenk8YjFn/build_Trunk_1/setup.py': [Errno 2] No such file or directory
     94{{{
     95<step id="test" description="Run unit tests">
     96  <python:distutils command="unittest"/>
     97  <python:unittest file="build/test-results.xml"/>
     98  <python:trace summary="build/test-coverage.txt" coverdir="build/coverage" include="trac*" exclude="*.tests.*"/>
     99</step>
     100}}}
     101!ToDo: Configure a Bitten task to run: http://localhost/Selenium/TestRunner.html?auto=true
    27102----
    28103DeveloperGuidelines