Junitee [transfer]

zhaozj2021-02-12  133

Junitee

Translation: slovenboy

Email: Slovenboy at Yahoo Dot CoM Dot CN

BLOG:

http://slovenboy.blogdriver.com

Resembling and publishing: Please keep the translator information and contact me

TUTORALIAL

This guide will explain how to use Junitee to do unit testing of EJB.

All source code in Junitee's distribution (Distribution)

Of the example directory, you can also online (

http://www.junitee.org/tutorial/index.html) Browse.

Implement EJB

The EJB used in this guide is a simple session bean for two digits. Check

Org.junitee.eb.einstein Source Codes in Packages Learn about the working mechanism in Beans.

The AddTwonumBers method has a small error to illustrate the effect of test failed, the method EMC2 is only

Throw an exception to cause test errors.

Write test case

The test case is a standard JUnit Test case (TESTCASE). For FixTure, you

You can use the default JNDI InitialContext to get the EJB reference, as follows:

Protected void setup () throws exception {context jndicontext = new initialContext ();

Object einRef = JNDICONTEXT.LOOKUP ("java: comp / eNV / EJB / Einsteinejb"); EinsteinHome Home = (EinsteinHome) PortableRemoteObject.Narrow (EinRef, EinsteinHome.Class);

THIS.EIN = home.create ();

Test method is like this:

Public void testsimpleaddition () THROWS RemoteException {string result = this.ein.addtwonumbers ("7", "10"); assert (Result.equals);}

The full code of the test case is included in the example - view the org.junitee.ejb.einstein.test package.

Create a front-end web form

The JUNITESERVLET performs the test case specified by the "Suite" form parameter, which can appear.

Use a simple form to start testing:

You May Type in the name of a test suite:


you may pick one or more of the following test suites: Create a web.xml deployment descriptor

The web application must be deployed to the right deployment descriptor, which provides EJB-Fef mapping

This "Java: Comp / ENV / EJB / EinsteineJB" JNDI query

Can work. JuniteServlet and its URL reflection in web.xml

Shooting is also necessary. This is an example:

"- // Sun Microsystems, Inc.//dtd Web Application 2.2 // En"

"

http://java.sun.com/j2ee/dtds/web-app_2_2.dtd ">

Einstein Unit Tester Web Application

juniteTSTSERVLET

Junitee Test Framework

org.junitee.servlet.juniteServlet

juniteTSTSERVLET

/ testservlet / *

EJB / EinsteineJB

Session

Org.infohazard.ejb.einstein.einsteinHome

Org.infohazard.ejb.einstein.einstein

Note: Orion Application Server has a defect in its URL mode matching algorithm, for Junitee

Cause some problems. If you use Orion, please modify the servlet mapping in the deployment descriptor.

juniteTSTSERVLET

/ testservlet *

Packing WAR files for testing

Now everything is ready to package the web application used to test. Must be placed

× junit.jar and junitee.jar to Web-INF / LIB

× Your test class to web-inf / classes or JAR files containing test classs to web-inf / lib

× Test front end form to index.html

× Web.xml to Web-INF

Finally, put all the files to Test.war using the JAR command and create an EAR file to include Test.war and

Contains EJB JAR files for Einstein Bean.

Run test

After deploying the EAR file, point your browser to the index.html file in the Test.war file and select Einsteintest.

Execute it. After a few seconds, the browser will display the test report, explain the successful and failed test.

= Make your work easier

Now you have learned how to create a .war file that contains Junitee Servlet and your test class. To create a WAR

Documents take a few steps, but fortunately, there is an automatic implementation of these steps: useful to create JUniteEwartask for Ant.

Take a look at Ant Howto (

http://www.junitee.org/antguide.html) Learn more content related to this task.

note

When you do unit testing for EJBs, you need to keep in mind:

× Unless you have a very careful write unit test unless you (and any item), it is easy to destroy the database.

Maybe you have never run test on a product system, in order to prevent this

Do (and other security reasons) You should not enable test web applications on the product machine.

× Test the getter and setter method perhaps waste time

reference

You may be interested in and / or feel useful resources:

× Get information on JUnit, access JUnit homepage (

http://www.junit.org).

× understand the limit programming, you can read "Extreme Programming: General Introduction" (

http://www.extremeprogramming.org/)

Then visit XProgramming.com (

http://www.xprogramming.com/) Website. × A excellent pattern, the resource of the anecdote and other useful information is portland Pattern RepOstory

(

http://www.c2.com/cgi/wiki?welcomevisitors website. You can from EjBUnittest

(

http://www.c2.com/cgi/wiki?ejbunittest "page or junitee

http://www.c2.com/cgi/wiki?junitee)

The page starts.

--------------------------------

postscript

This article has a lot of shortcomings, welcome criticism to correct :)

转载请注明原文地址:https://www.9cbs.com/read-6977.html

New Post(0)