Managed web hosting - Working with JUnit test cases Working with JUnit
Working with JUnit test cases Working with JUnit test cases This section explains how to use the EJB Test Client wizard to create a JUnit test case and how to run it. Creating a JUnit test case JUnit is an open source framework for unit testing written by Erich Gamma and Kent Beck. JUnit provides a variety of features which support unit testing, among them two classes, junit.framework.TestCase and junit.framework.TestSuite, which are used as base classes for writing unit tests. JUnit also provides three different kinds of test runners, TextUI, SwingUI, and AwtUI. Of these three test runners, two of them, TextUI and SwingUI, are available within the JBuilder IDE. The EJB Test Client wizard can generate a JUnit test case (a class that extends TestCase) for testing your EJB. To create and run a JUnit test for an EJB, you need the following: A properly configured server that supports EJB services. A project which has the correct server selected on the Server page of the Project Properties dialog box. An EJB, contained in an EJB Module. A JUnit EJB test client, which you can create with the EJB Test Client wizard. A Server type runtime configuration that uses the correct server settings. See Creating a Server runtime configuration on page 96. A Test type runtime configuration. The simplest way to create this is to check Create A Runtime Configuration in the last step of the EJB Test Client wizard when you create your JUnit EJB test client. This helps ensure that the Test runtime configuration has the proper settings. See also Configuring the target server settings in Developing Applications for J2EE Servers Creating a Server runtime configuration on page 96 Unit Testing in Building Applications with JBuilder Setting runtime configurations in Building Applications with JBuilder Creating a JUnit test case using the EJB Test Client wizard The EJB Test Client wizard can generate three different types of test clients for your EJB. One of these is a standard JUnit test client. Another type of JUnit test client is a Cactus JUnit test client, but that s discussed later. To generate a standard JUnit test client for your EJB, 1 Select File|New. 2 Select EJB Test Client on the Enterprise|EJB page of the object gallery. Click OK. The EJB Test Client wizard opens. 3 Select the JUnit Test option. 4 Click Next to go to the next step of the EJB Test Client wizard. 5 Select the bean you want to create a client for using one of the Select EJB options and specify the bean: Select From Project if your bean is in the current project and specify which bean by selecting it from the drop-down list. Select From JAR Or Directory if your bean is not in the current project, but exists elsewhere in a JAR file or a directory. Use the ellipsis ( ) button to navigate to 98 Developing Applications with Enterprise JavaBeans