Generating sample data in Java classes

Associate
Joined
6 Dec 2002
Posts
661
Location
Belfast
I use Eclipse for Java development and I have created a 'dummy' web service from a WSDL provided from a 3rd party. This is so we can test our client application. I generated the web service using the Eclipse WTP and this in turn has generated a lot of classes that correspond to the data objects defined in the schema. All member variables of these Java classes have been initialized to null resulting in the inability to test the web service effectively.

My question is, do any of you know a way of quickly generating sample data in these classes? For example, one of the member variables is priceOfLand and I would like this initialised to 123.45.

I hope you understand what I'm on about here, and any help would be very much appreciated.
 
Read up on unit testing, with the use of mock objects for sample data.

Also, surely your classes will have accessors to set the data (or rather change value from null)? Just use those.
 
Dj_Jestar said:
Read up on unit testing, with the use of mock objects for sample data.

Also, surely your classes will have accessors to set the data (or rather change value from null)? Just use those.
I will have a look at the unit testing stuff, thanks. And yes the objects do have setters but it would take a considerable amount of time to populate all of the data. I thought (naively) that there would be someway in Eclipse to easily generate sample data.
 
The only way to test effectively is to test with real-world examples, or rather examples that would be acceptable in a live instance. Unit testing does this on a micro-scale, but you'll have to test it as if it were in a live application (which should hopefully be obvious..) so if your setting takes ages in live environment, it will take ages in testing.

However mock-objects, also known as partial objects (which are simply objects created to give a single response without any logic) can circumvent the need to generate a long list of dependencies.
 
Dj_Jestar said:
The only way to test effectively is to test with real-world examples, or rather examples that would be acceptable in a live instance. Unit testing does this on a micro-scale, but you'll have to test it as if it were in a live application (which should hopefully be obvious..) so if your setting takes ages in live environment, it will take ages in testing.

However mock-objects, also known as partial objects (which are simply objects created to give a single response without any logic) can circumvent the need to generate a long list of dependencies.
All I need are these mock-objects for the time being so that we can get some sample data in the response message. How do I generate these mock-objects in Eclipse?
 
You create them yourself. :)

They simply satisfy an interface in the least complex way.

Code:
interface ExampleInterface
{
    public boolean someMethod();
}
class ExampleMockObject implements ExampleInterface
{
    public boolean someMethod()
    {
        return true;
    }
}

EDIT: another implementation is to have the mock object implement your real object.
 
Last edited:
Back
Top Bottom