473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Isolation testing, need suggestion

Hi,
I am thinking about ways for efficient techniques for isolation testing.
Here is the problem as I see it:
Complex OO systems are designed with massive number of dependencies between
modules and classes. In most cases these dependencies end-up in external
systems such as databases and OS. Overhead in designing systems with "could
be stubbed" in mind is great, so in many cases dropped.

I would appreciate if anyone interested in this problem could share his/her
opinion on possible approaches for isolation testing. I also attached some
code with my approach to it. It is based on introducing template parameter
with explicit template instantiation and specification.

Some comments to example and code:
Existing system:
- ImageDB class responsible for reading / writing images to database.
- Image class responsible for retrieval of required image from database,
processing it and storing back to database and depends on ImageDB class.
- Both classes are in middle of developed, many function are not yet fully
implemented.

Task:
- Create test unit for processing functionality (Image::clear() method)
without overhead related to preparing and populating DB with test data.
- Calls to Image and ImageDB classes should keep the same syntax.

Files (sorry for bulky example):
Before (code without stubbing facilities):
======================
// file: app/main.cpp
#include "image.h"
int main( )
{
Image img;
img.load( "John Doe" );
img.clear( );
return 0;
}

----------------------
// file: app/image.cpp

#ifndef __IMAGE_H__
#define __IMAGE_H__

#include <string>
#include "../services/imagedb.h"

class Image
{
public:
Image( );
~Image( );
void load( const std::string& name );
void clear( );

private:
void deallocate( );
ImageDB imageDB_;
size_t width_;
size_t height_;
unsigned int* buffer_;
bool isLoaded_;
std::string name_;
};

#endif // __IMAGE_H__
----------------------
// file: app/image.h
#ifndef __IMAGE_H__
#define __IMAGE_H__

#include <string>
#include "../services/imagedb.h"

class Image
{
public:
Image( );
~Image( );
void load( const std::string& name );
void clear( );

private:
void deallocate( );
ImageDB imageDB_;
size_t width_;
size_t height_;
unsigned int* buffer_;
bool isLoaded_;
std::string name_;
};

#endif // __IMAGE_H__
------------------------------
// services/imagedb.h

#ifndef __IMAGEDB_H__
#define __IMAGEDB_H__

#include <string>

class ImageDB
{
public:
ImageDB( );
bool getImageByName( const std::string& name, unsigned int*& buffer,
size_t& width, size_t& height );
bool setImageByName( const std::string& name, unsigned int* buffer,
size_t width, size_t height );
};

#endif // __IMAGEDB_H__

------------------------------
// services/imagedb.cpp

#include "imagedb.h"

ImageDB::ImageDB( ) {
throw 1; // cannot connect to database
}

bool ImageDB::getImageByName( const std::string& name,
unsigned int*& buffer, size_t& width,
size_t& height ) {
return false; // not implemented yet
}

bool ImageDB::setImageByName( const std::string& name,
unsigned int* buffer, size_t width,
size_t height ) {
return false; // not implemented yet
}

===========================
After (with some stubbing facilities and implemented unit test):
===========================
// file: utest/utest.cpp
#include <string>

struct TestImageProc { };
#define __DIAGNOSTICS__ TestImageProc

#define private public
#include "../app/image.h"
#undef private

// Stubbing ImageDB ctor, so it doesn't throws exception
template< > ImageDBT< TestImageProc >::ImageDBT( ) {}

// Stubbing ImageDB functionality, so it now returns 'true'
template< > bool ImageDBT< TestImageProc >::setImageByName(
const std::string& s, unsigned int* b,
size_t w, size_t h ) {
return true;
};

// Stubbing Image constructor, so we do not 'delete [ ] buffer_'
template< > ImageT< TestImageProc >::~ImageT( ) { };

int main( ) {
// test inputs, test setup
Image img;
img.width_ = img.height_ = 2;
unsigned int buf[ ] = { 1, 1, 1, 1 };
img.buffer_ = buf;
// test
img.clear( );
if( buf[ 0 ] != 0 )
{
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
---------------
// file: services/imagedb.h

#ifndef __IMAGEDB_H__
#define __IMAGEDB_H__

#include <string>

template< typename Diagnostics >
class ImageDBT {
public:
ImageDBT( );
bool getImageByName( const std::string& name, unsigned int*& buffer,
size_t& width, size_t& height );
bool setImageByName( const std::string& name, unsigned int* buffer,
size_t width, size_t height );
};

#ifndef __DIAGNOSTICS__
typedef ImageDBT< void > ImageDB;
#else
typedef ImageDBT< __DIAGNOSTICS__ > ImageDB;
#include "imagedb.cpp"
#endif

#endif // __IMAGEDB_H__
---------------
// file: imagedb.cpp
#include "imagedb.h"

#ifndef __DIAGNOSTICS__
template class ImageDBT< void >;
#endif

template< typename D >
ImageDBT< D >::ImageDBT( ) {
throw 1; // not yet defined
}

template< typename D >
bool ImageDBT< D >::getImageByName( const std::string& name, unsigned int*&
buffer,
size_t& width, size_t& height ) {
return false; // not yet implemented, fails
}

template< typename D >
bool ImageDBT< D >::setImageByName( const std::string& name, unsigned int*
buffer,
size_t width, size_t height ) {
return false; // not yet implemented, fails
}
---------
// file: app/main.cpp
#include "image.h"
int main( ) {
Image img;
img.load( "John Doe" );
img.clear( );
return 0;
}
-----------------------
// file: app/image.h
#ifndef __IMAGE_H__
#define __IMAGE_H__

#include <string>
#include "../services/imagedb.h"

template< typename Diagnostics >
class ImageT {
public:
ImageT( );
~ImageT( );
void load( const std::string& name );
void clear( );
private:
void deallocate( );
ImageDB imageDB_;
size_t width_;
size_t height_;
unsigned int* buffer_;
bool isLoaded_;
std::string name_;
};

#ifndef __DIAGNOSTICS__
typedef ImageT< void > Image;
#else
typedef ImageT< __DIAGNOSTICS__ > Image;
#include "image.cpp"
#endif
#endif //__IMAGE_H__

-----------------

// file: app/image.cpp

#include "image.h"
#include <stdexcept>

#ifndef __DIAGNOSTICS__
template class ImageT< void >; // explicite instanciation of version without
stubbing
#endif

template< typename D > ImageT< D >::ImageT( ):
width_( 0 ), height_( 0 ), buffer_( NULL )
{ }

template< typename D > ImageT< D >::~ImageT( ) {
deallocate( );
}

template< typename D > void ImageT< D >::load( const std::string& name ) {
deallocate( );
isLoaded_ = imageDB_.getImageByName( name, buffer_, width_, height_ );
name_ = name;
}

template< typename D > void ImageT< D >::clear( ) {
if( isLoaded_ ) {
unsigned int* end = buffer_ + width_ * height_;
for( unsigned int* p = buffer_; p != end; ++p ) {
*p = 0;
}
imageDB_.setImageByName( name_, buffer_, width_, height_ );
}
}

template< typename D > void ImageT< D >::deallocate( ){
delete [ ] buffer_;
buffer_ = NULL;
width_ = height_ = 0;
isLoaded_ = false;
name_.empty( );
}
Jul 19 '05 #1
3 2273
Andrew wrote:
Hi,
I am thinking about ways for efficient techniques for isolation testing.
Here is the problem as I see it:
Complex OO systems are designed with massive number of dependencies between
modules and classes. In most cases these dependencies end-up in external
systems such as databases and OS. Overhead in designing systems with "could
be stubbed" in mind is great, so in many cases dropped.

I would appreciate if anyone interested in this problem could share his/her
opinion on possible approaches for isolation testing. I also attached some
code with my approach to it. It is based on introducing template parameter
with explicit template instantiation and specification.


Briefly.

We have a system which we call unit testing. For each class
created a subsidiary test class is created. So if we have a
class NurbSurface then there is a class NurbSurfaceTest
which is a friend of NurbSurface, this is so that the test
class can examine the private data of the class under test.

Typically the test class will perform white box testing of
all the methods of the class it is examining. Auxiliary
functions are created for providing complex classes with
test data, in your case populating a test database.

We have scripts for creating boilerplate test classes and
test harnesses.

Each test is self contained requiring no tester input other
than to run the test program. Actually the complete suite of
tests are run unattended, and automatically overnight.

Similar systems are in place for testing class integration
and the main application.

Developers are not allowed to submit code changes unless all
the unit, integration, and application tests have been run
without any failures.

Any new functionality must be amenable to automatic
testing, which may require the development of additional
test/debug commands being added to the application.

All our tests are designed to crash the application or test
program on detecting an error.

Jul 19 '05 #2
sy***@msn.com (Andrew) writes:
Hi,
I am thinking about ways for efficient techniques for isolation testing.
Here is the problem as I see it:
Complex OO systems are designed with massive number of dependencies between
modules and classes. In most cases these dependencies end-up in external
systems such as databases and OS. Overhead in designing systems with "could
be stubbed" in mind is great, so in many cases dropped.

I would appreciate if anyone interested in this problem could share his/her
opinion on possible approaches for isolation testing. I also attached some
code with my approach to it. It is based on introducing template parameter
with explicit template instantiation and specification.
One possible approach are Mock Objects - Objects that have the same interface
as the real Objects, but are much easier to set up, e.g. for a database:

struct DBInterface {
virtual DataList getDataForQuery(const std::string& query) = 0;
virtual ~DBInterface() {}
};

struct MockDBInterface: public DBInterface {
DataList getDataForQuery(const std::string&) {
// return predefined DataList
}
};

struct OracleDBInterface: public DBInterface {
DataList getDataForQuery(const std::string&) {
// connect to Database, execute query, return results
}
};

of course, in your client code you'll have to use the DBInterface class
rather than the real OracleDBInterface class - but that seems like a
good idea, anyway.
For further reading on Mock Objects, go to

http://www.connextra.com/aboutUs/mockobjects.pdf

<SNIP>
----------------------
// file: app/image.cpp

#ifndef __IMAGE_H__
#define __IMAGE_H__


That's a very bad idea (TM) - any name containing two consecutive
underscores is reserved to the implementation, as well as any name
starting with an underscore followed by an uppercase letter - or
any name starting with an underscore visible in the global
namespace.
In short - don't use double underscores or leading underscores
for your identifiers / macros.

HTH & kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Jul 19 '05 #3

"Andrew" <sy***@msn.com> wrote in message
news:a1**************************@posting.google.c om...
Hi,
I am thinking about ways for efficient techniques for isolation testing.
Here is the problem as I see it:
Complex OO systems are designed with massive number of dependencies between modules and classes. In most cases these dependencies end-up in external
systems such as databases and OS. Overhead in designing systems with "could be stubbed" in mind is great, so in many cases dropped.

I would appreciate if anyone interested in this problem could share his/her opinion on possible approaches for isolation testing. I also attached some
code with my approach to it. It is based on introducing template parameter
with explicit template instantiation and specification.

Some comments to example and code:
Existing system:
- ImageDB class responsible for reading / writing images to database.
- Image class responsible for retrieval of required image from database,
processing it and storing back to database and depends on ImageDB class.
- Both classes are in middle of developed, many function are not yet fully
implemented.

Task:
- Create test unit for processing functionality (Image::clear() method)
without overhead related to preparing and populating DB with test data.
- Calls to Image and ImageDB classes should keep the same syntax.

....

I think you are bit off-topic here. You can try in group
comp.software.extreme-programming. This group is related to XP method which
is tightly linked to unit testing. The thing is: if you can't simply test
the class, class probably is not designed well. You have strong dependancy
on implementation of ImageDB class and because of that it is not possible to
simply test it. Image class, besides providing storage for the image data,
provides for loading from database. If you separate this tasks, your
testing will be much easier. You have increased coupling and lowered class
cohesion by not separating this tasks, which is usually bad. But then
againg, it depends on the context of problem you are trying to solve.

Regards,
Goran
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
3
by: Matthew Roberts | last post by:
To all SQL gurus: I have a Windows Service that uses a single SQL Server table to retrieve items of work. Each thread of the service checks this table for the earliest item of work that is not...
2
by: klh | last post by:
We use DB2 Connect v 7.2 FP7 in Windows NT hitting a OS/390 DB2 v7.1 database. We have a Websphere (java) application that issues dynamic SQL. Most of the time when we issue dynamic SQL SELECT...
9
by: yu_sha | last post by:
Hello everyone We have a bunch of components registered under COM+ with 'transaction required' option. On the client we are using iSeries Access 5.2.0, with all possible fixes applied...
2
by: John McGuire | last post by:
We have an web application about to go live with a customer. The app is ASP.Net 1.1 Framework with an Oracle DB backend. We have done performance tests on a W2K (IIS 5.0) test web server at our...
2
by: kanda | last post by:
Hello. I am developing the application (VBA&ODBC, to be exact) which periodically calls the stored procedures in the IBM DB2. A few of the procedures require executing with isolation level RR (...
3
by: joshsackett | last post by:
I am redesigning an application that distributes heldesk tickets to our 50 engineers automatically. When the engineer logs into their window a stored procedure executes that searches through all...
5
by: m0002a | last post by:
Is there some way to track the isolation level of an indivual SQL statement submitted via JDBC in a snaphot or some other similar means? I have JDBC programs that are changing the isolation level...
3
by: RG | last post by:
How can I lookup the current isolation level? Thanks in advance
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.