Thursday, November 29, 2007

JUnit Mock Object and JPerf

JUnit is good when writing reusable simple common package. When we try to write JUNIT for business components its always difficult, because of multiple interactions with different servers/components. How to handle this situation? for example, when server X is down system should take alpha path otherwise continue with beta path. Best approach is with Mock object, Mock objects are simple java class which represents external system/components. We can easily simulate this situation by setting status of mock object as "DOWN". So it throws back ServerUnAvailable exception.

Mock object has close relationship with stub, but stub just represents object; does not contain status.

Following are good on this topic,
1. Wiki
2. Article

Why JPERF here, i needed to refresh JPERF for our load testing now so :)

Good thing about JPERF is, its built to run JUNIT test cases. So we don't need to spend time on writing separate code for Load testing. Existing JUNIT code can be easily extended for load testing,

Example code,

int users = 10;int iterations = 20;
Timer timer = new ConstantTimer(1000);
Test testCase = new ExampleTestCase("testOneSecondResponse");
Test repeatedTest = new RepeatedTest(testCase, iterations);
Test loadTest = new LoadTest(repeatedTest, users, timer);

How simple? more

1 comment:

Anonymous said...

[url=http://ivlkrwnnz.com]PkOlXTfGLhhAtkt[/url] - fpbjKGpJ - http://hhmgziigpu.com