Unit tests in the JBoss Seam framework

Source: Internet
Author: User
Tags java web jboss testng
unit tests in the JBoss Seam framework
Reprint please retain the author information:
Author: 88250
blog:http:/blog.csdn.net/dl88250
MSN & Gmail & qq:dl88250@gmail.com


I want to write this article for a long time because there are some configuration problems with the unit tests under seam, and the seam framework advocates most of the integration tests. So there are no details and examples of unit testing, whether it's seam's reference manual or other reference books (seam in Action, etc). As is known to all, unit testing is an essential part of ensuring quality or TDD, and the importance of the project is self-evident. In this paper, we illustrate how the unit test of Seam is carried out, and there are some wrong points please point out:-)

I. The difficulties and problems of unit testing under Seam 1. Seam Framework relies on the container environment
Not just Seam, the WEB framework is now very few can be in a pure javase environment can be run, so out of the container environment, the framework is not operational, in fact, it is meaningless. As long as the container is involved, it brings a lot of problems, and because of the different containers, the problem is complex.

2. The complexity of testing inside/outside containers
The containment test here is the context in which the application is taken in the container's environment after the application is deployed, that is, in the same environment (within the container) when the application is running, and tested. In other words, test cases and implementations are run in the container's environment. Outside the container test is the test environment through the remote access container, to the container of remote Seam components/remote EJB session Beans instance, in the test environment outside the container test.

3. The integrity of JBoss Community products

Seam is JBoss, JBPM is JBoss, etc. seam dependent environment is jboss. So, the container is not JBoss's words, two words: trouble. Although today's seam (ver 2.1.1) describes how to configure and use seam in a non-JBoss as in a document/example, the author's current attempt to successfully use seam's Advanced functionality, JBoss as/hibernate is not necessary 。 This also requires to do Seam unit test, you must have a lot of JBoss products have a certain understanding.

two. Problem solvingIn the final analysis, the unit tests under Seam are just not good or difficult to configure. To configure a ' class container ' environment to allow Seam to run.
1. Build ' class container ' environment
From the configuration point of view, we first need to build a container environment. Unzip the downloaded Seam and find the bootstrap inside the Conf and deploy directories and copy them to the test environment directory. Create the Web-inf directory under the test environment directory and place Seam's core profile components.xml here, as well as JSF, WEB deployment descriptors, and so on, in the Web-inf directory.

2. Sample Seam components to be measured in test cases
From the code point of view, it is critical to get an instance of the component to be tested. In the test code, you can get the required component instances from the seam framework through the org.jboss.seam.Component.getInstance () method, which is the key to unit test success.

3. Initialize Seam framework
The Seam framework and application need to be manually initialized in the test code, and the end of the test is also required to manually end the framework and application, which are operated through org.jboss.seam.context.Lifecycle.

4. Selection of test framework
This is not a critical issue relative to Seam unit testing, but it is important to select a test framework for your project. As is known to all, the two most commonly used test frameworks, JUnit and TestNG, here are a few simple summaries:
JUnit: For small projects, it's a small, powerful advantage for simple unit tests, and the mainstream IDE has features or plug-ins. But the integration test (the integration interface) is difficult.
TestNG: Suitable for any project, IDE support is not very good, but JUnit can do it all can do, and more detailed, applicable scenarios more extensive.

three. ExampleThe author is a project built with NetBeans IDE and Maven, and the specific configuration of unit tests under Seam and sample code snippets are as follows:


Class
if (!     Lifecycle.isapplicationinitialized ()) {lifecycle.beginapplication (new hashmap<string, Object> ());     New Initialization (new Mockservletcontext ()). Create (). Init (); Lifecycle.begincall (); }
To obtain an instance of the component to be tested:
Processdeftransformer = (processdeftransformservice) Component. GetInstance (Processdeftransformer.class); Assertnotnull (Processdeftransformer);
End:
Lifecycle.endapplication ();
Four. SummaryIn this paper, the author sums up the difficulties and problems of unit testing under Seam, and puts forward a solution. With the growing stability and maturity of Seam framework and the release of Webbeans specification, it is believed that Java Web,java EE will usher in a new era.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.