,然后单击 OK。IDE 将创建 CustomerFacadeBeanTest,并在 Source Editor 中打开它。
声明 private CustomerFacadeRemote customerFacade 对象:
...
public class CustomerFacadeBeanTest extends TestCase {
private CustomerFacadeRemote customerFacade;
...
注意:如果 Source Editor 提示无法找到 CustomerFacadeRemote,则在 Projects 窗口中右键单击项目节点并选择 Build Project 来构建项目。会出现错误。
将 setUp 方法更改如下:
...
protected void setUp() throws Exception {
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("ejb/CustomerFacadeBean");
customerFacade = ((CustomerFacadeRemoteHome)PortableRemoteObject.narrow(obj,
CustomerFacadeRemoteHome.class)).create();
}
...
将 testCreateCustomer 和 testGetCustomerName 方法更改如下:
...
public void testCreateCustomer() throws Exception {
System.out.println("PK:" + customerFacade.createCustomer("Foo","Bar"));
}
public void testGetCustomerName() throws Exception {
long id = customerFacade.createCustomer("Joe", "User");
assertEquals(1, getLastName("name").length());
}
...
使用CMP Beans生成主键值(5)
时间:2011-08-05
删除 testMethodName 方法的其余部分。
在 Projects 窗口中右键单击 Test Libraries 节点,并选择 Add JAR/Folder。将应用程序的 lib 目录中的 appserv-rt.jar 文件添加到测试类路径中。
按下 Alt-Shift-F 生成任何所需的 import 语句。
右键单击 CustomerModule 项目节点,然后选择 Deploy Project。IDE 将部署该项目。
在 Projects 窗口中选中 CustomerModule 项目,然后选择 Run > Test "CustomerModule"。IDE 将编译并运行测试,然后在 Output 窗口中显示以下输出。
init:
deps-jar:
compile:
Compiling 1 source file to C:\new\CustomerModule\build\test\classes
compile-test:
03-Aug-2005 12:42:11 com.sun.corba.ee.spi.logging.LogWrapperBase doLog
INFO: "IOP00710299: (INTERNAL) Successfully created IIOP listener on the specified host/port: all
interfaces/1502"
PK: 1123065661713
Testsuite: org.bank.CustomerFacadeBeanTest
Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 3.855 sec
------------- Standard Output ---------------
PK: 1123065661713
------------- ---------------- ---------------
------------- Standard Error -----------------
03-Aug-2005 12:42:11 com.sun.corba.ee.spi.logging.LogWrapperBase doLog
INFO: "IOP00710299: (INTERNAL) Successfully created IIOP listener on the specified host/port:
all interfaces/1502"
------------- ---------------- ---------------
test-report:
test:
BUILD SUCCESSFUL (total time: 6 seconds)
|