JUnit Testing in Curam
Curam out of the box comes with some rudimentary JUnit testing capability within their EJBServer project since around version 3. I've been using it instead of something I wrote up back in 2004 for my unit testing because at least it comes with Curam. However, my colleagues have told me that there have been no instructions on setting it up till now. So, this is my attempt at documenting what you need to do in order to get your Curam unit tests working.
Note: for those I have talked with on this subject before, this is a simpler way of doing things rather than what I have been doing in my previous projects.
Setting up a place for your unit tests
The first thing you would need to do is find a place to put your tests.
- Make a new source folder EJBServer\components\custom\tests. The last path element has to be tests.
- When I initially set things up, I always create a test package called curam.yourproject.test.sanity. In this folder I create a simple unit tests to prove that things work correctly. In which case I put in the following test and verify that it runs within Eclipse.
public SanityTest extends TestCase {public void testSanity() throws Exception {
assertTrue(true);}
}
Verifying that your unit test works in Curam
The next thing you need to deal with is running the actual test within Curam's build scripts. To do this you just have to type the following in the command prompt:
build supplement -Dsupplement=tests
build test
The supplement target creates a supplementary jar and will pull any sources that have the value of supplement in their source path. In this case it would be tests.
The test target runs the test cases and generates an HTML report. The report is located in EJBServer\build\testresults\html\index.html.
Creating a Curam Server Test case
Before you create a Curam server test case, you need to ensure that curam.test.framework.CuramServerTest is in your build path. To do this, just set EJBServer\components\core\tests as a source folder and set it to include only curam.test.framework.CuramServerTest. The other files are used by the build scripts and won't compile cleanly in Eclipse without making additional changes to the build path that you don't really need.
I would the create a simple test case that looks like:
public CuramSanityTest extends CuramServerTest { /** * This is needed because Curam is using an * older version of JUnit which requires the * one argument constructor. */ public CuramSanityTest(final String name) {super(name);
}
public void testSanity() throws Exception {
assertTrue(true);}
public void testOrganizationListUserForOrganization() throws Exception {
OrganizationFactory.newInstance().listUserForOrganisation();
}
}
Then I rerun the test to see if it works out on Eclipse and on the command line.
Special directories
Curam's command line tester will test every single file in the tests.jar with the exception of a few folders unless you modify app_test.xml. However, if you want to avoid having to make changes to the build scripts, use the server.curam.test.utility package to contain your utility classes.
Setup and Teardown
Curam's test framework extends the setUp and tearDown methods with setUpCuramServerTest and tearDownCuramServerTest respectively. Unfortunately, they did not make them throw Exception. So unless you make your own copy of the CuramServerTest, which I normally do in my projects to eliminate the need for the constructor, you would have to wrap your setUp and tearDown routines with a try-catch block that throws a RunTimeException for example:
protected void setUpCuramServerTest() {
try {...
} catch (Exception e) {throw new RuntimeException(e);
}
}
Thanks
Kudos to Robert S. for encouraging me to write this. Good luck on your project Rob and sorry if this is simpler than the way you tried to copy from us!

0 comments:
Post a Comment