Peter Edwards - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Peter Edwards

Description:

Content Management System used at BBC to enter XML documents ... Shortcuts, registry Win32::OLE, unzipping archives to Windows Apps dir etc. Solutions ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 16
Provided by: Petere67
Category:
Tags: edwards | ole | openvms | peter

less

Transcript and Presenter's Notes

Title: Peter Edwards


1
Real Life Cross-Platform Testing
  • Peter Edwards

peter_at_dragonstaff.co.uk
MiltonKeynes.pmPerl Technical Talk8th July 2008
2
Contents
  • Background aka "Real Life"
  • Cross-Platform
  • Testing
  • Add Windows Testing Under Unix
  • TestMockObject
  • TestMockModule
  • Running Unix unit tests under Windows
  • Future Plans For Testing
  • Summary and Links

3
Background aka "Real Life"
  • Content Management System used at BBC to enter
    XML documentsthat are later transformed to make
    public websites
  • Client-side
  • GUI using WxPerl (WxWidgets)
  • WYSIWYG editing
  • Talks SOAP over HTTP to server
  • Runs under ActiveState Perl
  • Server-side
  • Handles SOAP requests
  • Stores document blobs in filesystem
  • Stores indexes, metadata in Oracle database
  • Runs under Solaris Perl
  • Usage
  • 100s of users
  • Time critical publishing failure during release
    is not an option

4
Cross-Platform
  • CMS code running on Windows and Solaris
  • Solaris perl 5.8.8
  • perl -V
  • Summary of my perl5 (revision 5 version 8
    subversion 8) configuration
  • Platform
  • osnamesolaris, osvers2.10,
    archnamesun4-solaris
  • Windows ASPerl 5.8
  • C\WINNTgtperl V
  • Summary of my perl5 (revision 5 version 8
    subversion 6) configuration
  • Platform
  • osnameMSWin32, osvers4.0,
    archnameMSWin32-x86-multi-thread

5
Testing
  • Unit tests for dev
  • Automated overnight smoke testing of unit tests
  • Dev / Staging Test / Live environments
  • Manual release test on staging test area using
    Windows app
  • Problems
  • Lots of tests for server side code, very few for
    client side because difficult to run 'use Wx'
    code on Unix in batch
  • Existing tests run on Unix, fail on Windows

6
Add Windows Testing Under Unix
  • Need to write lots of client-side tests for
  • GUI
  • WxPerl -gt Gtk under Solaris
  • Use Wx was failing because no X display
  • Problems with font sizing and window alignment
  • Windows-specific components, e.g. ActiveX Altova
    editor
  • Installation
  • Shortcuts, registry Win32OLE, unzipping
    archives to Windows Apps dir etc.
  • Solutions
  • Use Xvfb
  • alias runxvfb'Xvfb 10 -dev vfb screen 0
    1152x900x8 gt /dev/null 2gt1 '
  • Lets you check code compile and call many
    routines
  • But how do you test UI rendered properly -
    interpreting the virtual screen bitmaps is too
    hard!
  • Sandboxing and mocking
  • Mock required Win32 functions
  • Make them do file I/O to a sandbox area
  • TestMockObject - Perl extension for emulating
    troublesome interfaces
  • TestMockModule - Override subroutines in a
    module for unit testing

7
TestMockObject 1
  • Helpers
  • sub make_mock_obj_in_class
  • my class shift
  • my obj TestMockObject-gtnew
  • obj-gtfake_module(class)
  • obj-gtfake_new(class)
  • return obj
  • sub dump_mock_calls
  • my mockobj shift
  • my i 1
  • while ( my name mockobj-gtcall_pos(i)
    )
  • diag " call i name"
  • my _at_args mockobj-gtcall_args(i)
  • for (0 .. args)
  • diag ' arg '.(_ 1).' '
  • diag Dumper(args_)

8
TestMockObject 2
  • Mocking
  • my wx make_mock_obj_in_class( 'Wx' )
  • my mock_WxPerlSplashProgress
    make_mock_obj_in_class( 'WxPerlSplashProgress'
    )
  • mock_WxPerlSplashProgress-gtset_true(qw(
    SetLabelColour SetIcon Show SetValue Update
    Destroy ))
  • mock_WxPerlSplashProgress-gtmock( SetLabel gt
    sub diag ' SetLabel '._1 )
  • mock_Win32OLE make_mock_obj_in_class(
    'Win32OLE' )
  • mock_Win32OLE-gtmock( 'SpecialFolders', sub
    shift )
  • mock_Win32OLE-gtmock( 'AppData', sub return
    catdir(qw(data win32), 'Application Data') )
  • mock_Win32OLE-gtmock( 'StartMenu', sub
    catdir(qw(data win32 startmenu)) )
  • mock_Win32OLE-gtmock( 'Desktop', sub
    catdir(qw(data win32 desktop)) )
  • mock_Win32Shortcut make_mock_obj_in_class(
    'Win32Shortcut' )
  • mock_Win32Shortcut-gtmock( 'Load', sub
  • my (self, filename) _at__
  • self-gtcontent read_file(filename)
  • return 1

9
TestMockObject 3
  • Testing
  • mock_WxPerlSplashProgress-gtclear()
  • is( i-gt_install_loginscript, 1,
    'i-gt_install_loginscript' )
  • dump_mock_calls(mock_IFLDesktopLoginScript)
  • mock_IFLDesktopLoginScript-gtcalled_pos_ok( 3,
    'install', 'called IFLDesktopLoginScript-gtinst
    all' )
  • dump_mock_calls(mock_WxPerlSplashProgress)
  • mock_WxPerlSplashProgress-gtcalled_pos_ok( 4,
    'SetLabel', 'called WxPerlSplashProgress-gtSetL
    abel' )
  • mock_WxPerlSplashProgress-gtcalled_args_pos_is(
    4, 2, 'Checking login script' )
  • mock_WxPerlSplashProgress-gtcalled_pos_ok( 7,
    'SetLabel', 'called WxPerlSplashProgress-gtSetL
    abel' )
  • mock_WxPerlSplashProgress-gtcalled_args_pos_is(
    7, 2, 'Installing login script...' )

10
TestMockModule 1
  • Helper
  • sub mock_module
  • my (module,options,_at_functions) _at__
  • my no_auto defined(options-gtno_auto)
    ? options-gtno_auto 1
  • my create_new defined(options-gtcreate
    _new) ? options-gtcreate_new 1
  • my testmockmodule new
    TestMockModule(module, no_auto gt no_auto)
  • my object
  • if (create_new)
  • object bless , module
  • testmockmodule-gtmock('new',sub
    logger-gtlog(module,'new',_at__) return object
    )
  • for my function (_at_functions)
  • testmockmodule-gtmock(function,sub
    logger-gtlog(module,function,_at__) )

11
TestMockModule 2
  • Mocking
  • my (mock_wx_activex_ie, mock_wx_activex_ie_objec
    t)
  • mock_module('WxActiveXIE',)
  • my (mock_wx_activex_event, mock_wx_activex_event
    _object)
  • mock_module('WxActiveXEvent',,_at_Wx
    EventEXPORT_OK)
  • my (mock_wx_panel,mock_wx_panel_object)
  • mock_module('WxPanel',, qw(
    SetSizer ))
  • my (mock_wx_boxsizer,mock_wx_boxsizer_object)
  • mock_module('WxBoxSizer',, qw( Add
    ))
  • Tests - use your objects as normal then check
    call sequence
  • my _at_mf_calls logger-gtfilter('FLIPClientUIM
    icroForms' gt )
  • my call shift(_at_mf_calls)
  • is(call-gtfunction,'set_template','position_chan
    ge (' . test-gtname . ') calls set_template')
  • ok(call-gtargs-gt1 test-gttemplate,'positi
    on_change (' . test-gtname . ') sets
    template')
  • call shift(_at_mf_calls)
  • is(call-gtfunction,'set_data','position_change
    (' . test-gtname . ') calls set_data')
  • is_deeply(call-gtargs-gt1,test-gtdata,'positi
    on_change (' . test-gtname . ') sets data')

12
Running Unix unit tests under Windows 1
  • Some libraries shared between Unix and
    Windowsnot being tested properly client-side
  • Perl Portability
  • "perldoc perlport http//perldoc.perl.org/5.8.8/p
    erlport.html"When the code will run on only two
    or three operating systems, you may need to
    consider only the differences of those particular
    systems. The important thing is to decide where
    the code will run and to be deliberate in your
    decision.
  • Only worrying about Windows and Unix OpenVMS
    support is hard
  • binmode and chomp - binmode saves headaches on
    Windows like EOF Z watch out for CR-LF
  • use FileSpecFunctions rather than Unix paths
  • YES my path rel2abs( catdir(qw( data local
    cache file.txt ))
  • NO my path './data/local/cache/file.txt'

13
Running Unix unit tests under Windows 2
  • Generic configuration interface with
    platform-specific subclasses
  • System.pm
  • -- System/Win32.pm
  • -- System/Unix.pm
  • using FileSpecFunctions for paths
  • Change tests from path strings to regexes using a
    quote path separator
  • my script i-gtstartup('remote')
  • NO is( script, 'scripts/FLIP_real.PL',
    'i-gtstartup("remote") script
  • YES ps (O eq 'MSWin32') ? "\\" '/'
  • qps quotemeta ps
  • like( script, qr scripts qps
    FLIP_real.pl \z xms, 'i-gtstartup("remote")
    script' )
  • Note PBP style regex
  • Actually run the tests on multiple platforms

14
Future Plans For Testing
  • Automate application release test under Windows
  • Win32GuiTest (or pay for WinRunner)

15
Summary and Links
  • Summary
  • "perldoc perlport
  • Write cross-platform tests from the outset
    convert old ones
  • Mock platform-specific GUI or system library
    calls
  • Automate tests (life is short) and get as much
    coverage as possible
  • Links
  • WxPerl http//wxperl.sourceforge.net/
  • WxWidgets http//docs.wxwidgets.org/trunk/
  • "Perl Testing A Developer's Notebook" Ian
    Langworth chromatic, O'Reilly Media, Inc., 2005
    http//preview.tinyurl.com/5k6wnc
  • Thank you. Any Questions?
Write a Comment
User Comments (0)
About PowerShow.com