IBM WebSphere Adapters Network Card User Manual


 
JUnit: an open source framework for unit testing
JUnit is becoming the standard tool for unit testing in Java development
environments. JUnit allows you to quickly and easily integrate automated
regression testing into your coding and build processes.
With JUnit, an open source unit test framework, you can write and run tests for
your adapter implementation. You use a simple setup() method to prepare each
component for testing. Each test method can contain one or more assertions. The
assertions test actual results against expected results. Using JUnit assertions, you
can achieve a high degree of code quality and responsiveness to requirements
outside of the adapter runtime environment.
A simple JUnit test case resembles the following:
public class MyTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
}
public testSomething() throws Exception{
String result = classUnderTest.executeSomething();
assertEquals(result,"Something");
}
}
The setUp() method is called once before each test method. The purpose of the
setUp() method is to prepare the component for the test. You can create several
test methods; each must begin with the word test and contain at least one
assertion.
The next section shows how to use the setUp() method to prepare your adapter
for testing, and how to use the test methods to execute functions. Because the goal
is to test the adapter in unmanaged mode, you must run the adapter outside of a
JCA container.
Validating the adapter in unmanaged mode–testing the adapter as part of
development, gradually building the test case suite to address requirements–is a
first step. This prepares the adapter for managed testing in a runtime environment.
It also yields useful artifacts: the test case suite remains useful after unit testing
because changes in code that break the functionality are tracked, alerting you when
testing future iterations inside the development environment.
For more information about JUnit, see http://junit.org.
Developing JUnit tests
You unit test outbound and inbound processing by creating and specifying JCA
contracts and operations. You then test and compare data before and after applying
the tests. The TwineBall sample helps illustrate these steps.
Outbound
The J2EE Connector Architecture (JCA) specification defines an unmanaged mode
for running adapters. This means running the adapter outside of a JCA container
and in process with the caller. This is the environment for developing JUnit tests.
Through a series of common client interface (CCI) and service provider interface
(SPI) calls, you can force the adapter to perform an operation you want to test.
First you must create instances of ManagedConnectionFactory and ResourceAdapter
and then set the appropriate properties in the client code.
WebSphere Adapter development overview 195