titbits from the world less travelled

Archive for February, 2008

CPPUnit for Java developers – Part 2

In my previous post we had created the classes to be tested. Now we will create the actual test classes from where we call cppUnit.

helloWorldTest.h
————————
#ifndef CPP_UNIT_EXAMPLETESTCASE_H
#define CPP_UNIT_EXAMPLETESTCASE_H

#include cppunit/extensions/HelperMacros.h

class helloWorldTestCase : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE( helloWorldTestCase );
CPPUNIT_TEST( add );
CPPUNIT_TEST_SUITE_END();

protected:
int a;
int b;

public:
void setUp();

protected:
void add();

};

#endif
=======================================

helloWorldTest.cpp
——————-
#include cppunit/config/SourcePrefix.h
#include helloWorldTest.h
#include helloWorld.h

CPPUNIT_TEST_SUITE_REGISTRATION( helloWorldTestCase );

void helloWorldTestCase::add()
{
helloWorld* hw = new helloWorld();
int mySum = hw->add(a,b);
int sum = 10 + b;
CPPUNIT_ASSERT( mySum == sum );

//CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, 1.1, 0.05 );
//CPPUNIT_ASSERT( 1 == 0 );
//CPPUNIT_ASSERT( 1 == 1 );
}

void helloWorldTestCase::setUp()
{
a = 2;
b = 3;
}
——————————————————

Now we have all the files needed for running cppUnit. You will need to build the project once. Then goto Debug->Start without debugging(Ctrl+F5)
You will get the results.

posted by admin in Uncategorized and have No Comments

SoapUI – How to synchronize using threads during load test

I use soapUI to test webservices. I was facing this scenario when running load test. I had five threads. And when I ran these threads at the same time, each of the threads used to create its own local objects. I was reading a unique serialNo from a file and then processing it. Due to these threads , I was reading the serialNo five separate times.

In this situation I tried using FileLocking,plain synchronization..etc. It didnt work out as specified. So I used LoadTestContext. This can be called using the command context.LoadTestContext in the groovy script. You can use it as below :

// call the loadTestContext and store it in a local variable
def ltContext = context.LoadTestContext
try{
// synchronize the part of code in which you are accessing the variable.
synchronized(ltContext)
{
//serialNo is the code that I want to be synchronized for the threads.
//check for Null
if(ltContext.serialNo == null)
{
//get the serialNo from a file and write it to a file…

def writer1=new File(c:\testFiles\contentsContextError.txt).newWriter(true)
writer1.writeLine(Null Value+ltContext.serialNo)
writer1.close()

}else
{
//get the serialNo from the loadContext and store it
// in a local variable.

String serialNo = ltContext.serialNo;

log.info(set the value +ltContext.serialNo);
}
}
}catch(Exception e)
{
log.info(Error+e);
}

Remember the loadContext is null unless you run a load test.
In this way you can synchronize the threads in a load test in SOAPUI.

posted by admin in Uncategorized and have No Comments