From: Simon L. <sim...@uk...> - 2002-09-13 09:01:33
|
On Friday 13 September 2002 00:07, Steve Freeman wrote: > I'd like to see some concrete examples, especially for ExpectationMap > which is, itself a verifiable. It's sounds like some of your tests may > be going too deep. You can overspecify, as well as underspecify. > Concrete example: We've got our own JDBC Connection Pool implementation which like most has=20 a finite set of actual JDBC Connections that it can allocate to threads.=20 Each piece of code wanting to use JDBC talks directly to the Pool asking=20 for a connection to a particular named databaase (through a symbolic=20 name).=20 Thus the call to the Connection Pooling classes is performed within the=20 method we want to test. e.g: public Person getPerson(String name) { // PooledConnection is a wrapper round Connection PooledConnection conn =3D ConnectionPool.getPooledConnection("persondb"); try { conn.enable(); // Actually gets JDBC Connection from pool stmt =3D conn.prepareStatement(...); results =3D stmt.exeuteQuery(); person =3D new Person(results): } catch (SQLException e) { conn.disable(); } reutrn person; } I've developed a Mocked version of the Connection Pooling system to allow=20 these methods to be tested.=20 What happens is the setup calls on MockConnectionPool populate an=20 ExpectationMap from pool name to MockPooledConnection - so you can test=20 the expectation that certain database connections will be/are being used.=20 verify() is checking expected keys vs actual keys. What I'd like to automate is the verification of the expectations set on=20 the MockPooledConnection objects contained in the ExpectationMap (ie. its=20 values).=20 I think it would also be useful to check the MockStatements contained=20 therein, and their MockResultSets as well.=20 You can obviously manually do this at the moment however verifying the=20 expectations means keeping a lot of object references locally to the test=20 method for the duration of the whole test. Simon., =2D-=20 =2D------------------------------------------------------------------------- Simon Levitt, Senior Development Engineer @ WorldPay plc, WorldPay Centre, The Science Park, Milton Rd., Cambridge, CB4 0WE, ENGLAND = =20 Sim...@uk... Ph:+44(0)1223 715151 F:+44(0)1223 715157 =2D------------------------ http://www.worldpay.com/ ----------------------- |