672329 members! Sign up to stay informed.

Sponsored Links


Resources

Enterprise Java
Research Library

Get Java white papers, product information, case studies and webcasts

News News News Messages: 14 Messages: 14 Messages: 14 Printer friendly Printer friendly Printer friendly Post reply Post reply Post reply XML XML XML

In-Container Testing with JUnit

Posted by: Sudhakar Ramakrishnan on August 23, 2004 DIGG
Learn how in-container testing with JUnit adds a layer of integration testing that is most useful in practice. Examples used in this article will teach you how to make JUnit tests access objects running inside a J2EE container

Julien Dubois writes:
Thanks to the JUnit framework, it has become quite easy to write unit tests for simple Java applications. However, where real-world enterprise applications are concerned, the typical JUnit testXXX() method will not be as helpful because those applications require that objects run inside a container. Author further discusses how to apply those techniques using Oracle JDeveloper IDE.
In this article, I will describe the application of in-container testing in order to make JUnit tests access objects running inside a J2EE container. The example used here is a Struts-based Web application, which is fairly common among enterprise applications, but the techniques discussed are relevant to any J2EE project.
 
Read the article In-Container Testing with JUnit

Threaded replies

·  In-Container Testing with JUnit by Sudhakar Ramakrishnan on Mon Aug 23 17:48:46 EDT 2004
  ·  JUnitEE by Muito Axe on Tue Aug 24 10:22:22 EDT 2004
    ·  Cactus by Andrew Nortje on Tue Aug 24 12:26:13 EDT 2004
      ·  Cactus by Roland Barcia on Tue Aug 24 14:26:35 EDT 2004
      ·  JUnitEE by Muito Axe on Tue Aug 24 14:31:04 EDT 2004
    ·  JUnitEE by Archimedes Trajano on Tue Aug 24 13:17:44 EDT 2004
      ·  JUnitEE and cactus by mark lybarger on Wed Aug 25 09:24:48 EDT 2004
        ·  OpenEJB by Archimedes Trajano on Wed Aug 25 14:00:55 EDT 2004
          ·  OpenEJB, Cactus and MockEJB by Alexander Ananiev on Wed Aug 25 15:32:10 EDT 2004
  ·  In-Container Testing with JUnit by Nick Minutello on Tue Aug 24 15:30:41 EDT 2004
  ·  In-Container Testing with JUnit and DynamicJava -> no redeploy by Mads Peter Henderson on Wed Aug 25 05:45:27 EDT 2004
    ·  In-Container Testing with JUnit and DynamicJava -> no redeploy by Chester Chen on Thu Aug 26 17:16:31 EDT 2004
      ·  In-Container Testing with JUnit and DynamicJava -> no redeploy by Chester Chen on Thu Aug 26 17:35:22 EDT 2004
        ·  In-Container Testing with JUnit and DynamicJava -> no redeploy by chene yeuse on Fri Jul 08 08:50:41 EDT 2005
  ·  TestSessionBean by Kevin Grainer on Wed Aug 25 09:14:51 EDT 2004
  Message #135385 Post reply Post reply Post reply Go to top Go to top Go to top

JUnitEE

Posted by: Muito Axe on August 24, 2004 in response to Message #135266
Personally, for in-container testing (particularly of ejb components - and messaging) I have found JUnitEE to be one of the easiest and quickest tools to configure-
http://www.junitee.org/

  Message #135426 Post reply Post reply Post reply Go to top Go to top Go to top

Cactus

Posted by: Andrew Nortje on August 24, 2004 in response to Message #135385
I need to start doing server side testing. How does JUnitEE compare to Cactus?

  Message #135439 Post reply Post reply Post reply Go to top Go to top Go to top

JUnitEE

Posted by: Archimedes Trajano on August 24, 2004 in response to Message #135385
I liked and hated both Cactus and JUnitEE although I have less experience with the later.

JUnitEE is good if you have someone who has created a deployment script already for you and you can just run the test. Also the person needs to have created a report template for you as well. (Hopefully someone creates a Maven plugin to do this so it will be integrated with the rest of Maven's site report)

Cactus I find to be a better tool when you are automating tests and try to keep things more generic for multiple application servers. However, its fiendishly more complicated to set up, not really Cactus' fault, but more of the fault of the application server vendors itself (I do wish someone does create a standardized API to stop, start, deploy, undeploy to servers like Vincent Massol stated in his blog a while back). If you can get Cactus working on your environment especially with maven you'd probablly like it a lot better since you'd get your reports for free as well, but like I said, setup is a killer.

  Message #135454 Post reply Post reply Post reply Go to top Go to top Go to top

Cactus

Posted by: Roland Barcia on August 24, 2004 in response to Message #135426
Cactus also lets you write Unit Tests to unit Test Servlet. JSP, and Servlet Filters directly. Using a Struts extension to cactus, you can unit test Struts Actions directly. This is an additional value add for the web layer of J2EE apps. JUnitEE only provides an environment to run standard JUnit inside the container but no way to unit test Servlet, Action classes directly. Cactus will even work J2EE Security and supports Basic and Form Based Auth.

Cactus also provides a Mock framework for running these J2EE Web unit tests outside the container.

  Message #135455 Post reply Post reply Post reply Go to top Go to top Go to top

JUnitEE

Posted by: Muito Axe on August 24, 2004 in response to Message #135426
As mentioned- cactus is probably a bit more robust- and may be more appropriate for testing web tier components- such as servlets- as JUnitEE provides a servlet that lets you "tunnel" in to the container and call JUnit tests. It is very good for testing ejb components and messaging in this manner and I found it to take <1 hour to figure it out and deploy- whereas configuring cactus is a bit more cumbersome in my opinion- and would only use it if I were testing such web-tier items.

  Message #135472 Post reply Post reply Post reply Go to top Go to top Go to top

In-Container Testing with JUnit

Posted by: Nick Minutello on August 24, 2004 in response to Message #135266
Personally, I prefer to do as much testing as possible out of the container - and write my code accordingly.

Integration tests (end-to-end) is where running in the container is tested - but hopefully not too much behaviour is being tested here (that wasnt already tested in the out-of-container tests).

-Nick

  Message #135526 Post reply Post reply Post reply Go to top Go to top Go to top

In-Container Testing with JUnit and DynamicJava -> no redeploy

Posted by: Mads Peter Henderson on August 25, 2004 in response to Message #135266
In our projects, we have had the same need to be able to execute code inside the container, especially testing of local interfaces is hard to do, unless you want to provide a remote interface just for testing.

But having to redeploy the test case to the server, every time you have to change a testcase, as you have to do with the existing frameworks that I know of, quickly gets anoying. So what we have done is to write a TestFacade session bean with remote interface, which uses DynamicJava (hosted at sourceforge) to execute dynamicjava scripts. We then have an extension of Junit's TestCase which is able to read the scripts from the filesystem, and ask the TestFacade to execute it.

Every TestCase we have is then an extension of our own TestCase and a set of dynamicjava scripts, containing the business logic of the test.

  Message #135555 Post reply Post reply Post reply Go to top Go to top Go to top

TestSessionBean

Posted by: Kevin Grainer on August 25, 2004 in response to Message #135266
How about ServerTestCase? http://www.junit.org/news/extension/j2ee/index.htm#ServerTestCase. It's simple to set up and easy to use. Just extend ServerTestCase instead of TestCase and you are in-container.

  Message #135557 Post reply Post reply Post reply Go to top Go to top Go to top

JUnitEE and cactus

Posted by: mark lybarger on August 25, 2004 in response to Message #135439
not only is cactus a pain to setup, but it also takes a long time to run your tests. this is again due to the nature of the j2ee servers. assuming you're servers aren't running, you've got to start them up, deploy your components, run the tests, and then shut them down. we have slsb's that we need to test on a wls environment, and this is painfully slow.

i looked into Alex Rupp's (sp?) article on using openejb (and axion db) for testing incontainer. on the surface it looks really exciting, but there's not much documentation on configuring openejb, and maybe everyone there is busy working on the geronimo release, but it's hard to get answers to the mailing list ( i can't even subscribe to the list using my work email address, maybe it's down/moved?). my simple example test worked ok, but i had issues resolving the dtd's since i'm behind a proxy. it would be nice if there were docs, forums, etc up for this awesome ejb server.

still, each of these technologies provide something of value. the openejb approach, using an intra-vm container, is very very fast, and provides a test driven development environment. using cactus for tdd would be: write a test, start the test, get a coffee and snack, come back see the results, change the code, redo. cactus provides a reality check with your actual application server (and possibly database servers). if you decide you need to switch to a new database driver, or perhaps switch to a new database, how can you quickly see where the problems are? run the bundle of cactus tests and see how it goes.

  Message #135612 Post reply Post reply Post reply Go to top Go to top Go to top

OpenEJB

Posted by: Archimedes Trajano on August 25, 2004 in response to Message #135557
Although I like the concepts put forward by N.A.Rupp's article, (I am actually waiting for Geronimo to come out so we have an EJB container that supports 2.0). I still like to have Cactus as one of my tests. Primarily, its good to test on the server you are deploying on, especially with the slight incompatabilities with all the application servers you want to make sure your generated app server specific deployment descriptor works properly.

I wouldn't really use cactus for running unit tests though, like it was specified earlier its too slow because of the startup and shutdown times of the application server. Its still good to run on your nightly build server where you don't really have to watch it run (once everything is set up).

I think any large project should have a build expert that can set up automated integrated test running using Cactus and be focused on improving the development infrastructure. (i.e., don't let the person get bogged in the application development stuff, make him focused on builds and performance reporting).

Also, I personally like to do most of my coding out of container as well. Usually if it is a brand new project methods can be applied to allow for that, but if you're not there from the beginning, you have to adapt as much as possible and from my current experience JUnitEE would be the best for retrofitting in developer unit tests along with either JFC/HttpUnit (if you're fortunate that your project uses standard HTML and can work without javascript or an automated mouse and keyboard robot to run through the web site or GUI client).

  Message #135626 Post reply Post reply Post reply Go to top Go to top Go to top

OpenEJB, Cactus and MockEJB

Posted by: Alexander Ananiev on August 25, 2004 in response to Message #135612
For out of container testing, I can recommend MockEJB framework that I developed (www.mockejb.org). Unlike OpenEJB, this is a mock container geared specifically for testing. So I use MockEJB for on-going development and Cactus for integration testing and verification of the deployment (MockEJB does not read deployment descriptors).

Alexander

  Message #135832 Post reply Post reply Post reply Go to top Go to top Go to top

In-Container Testing with JUnit and DynamicJava -> no redeploy

Posted by: Chester Chen on August 26, 2004 in response to Message #135526
This sounds interesting. I will check it out.

We are using using ServerSideTest JUnit extension.
It works fine except for the re-deployment. And For Weblogic Server, this become real pain as it takes long time to do the ejbc.



Chester

  Message #135837 Post reply Post reply Post reply Go to top Go to top Go to top

In-Container Testing with JUnit and DynamicJava -> no redeploy

Posted by: Chester Chen on August 26, 2004 in response to Message #135832
Correction, Not ServerSideTest, it should be ServerTestCase. Sorry.

  Message #177260 Post reply Post reply Post reply Go to top Go to top Go to top

In-Container Testing with JUnit and DynamicJava -> no redeploy

Posted by: chene yeuse on July 08, 2005 in response to Message #135837
hi,

how do you manage to use ServerTestCase?
I must miss something : I can't even run the ExempleServerTestCase.
I always get ClassNotFoundException.
Can somebody help me, please?

TIA

New content on TheServerSide.comNew content on TheServerSide.comNew content on TheServerSide.com

Dependency Injection in Java EE 6 - Part 2

Reza Rahman continues to explore the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6. (January 21, Article)

Ted Neward Q&A: What you must know about JavaScript, Scala and more

Ted Neward is an independent consultant specializing in high-scale enterprise systems, and an authority in Java and .NET technologies. He is the author and co-author of several books, including Effective Enterprise Java. At TheServerSide Java Symposium in March, he will be presenting sessions on pragmatic architecture, ECMAScript and Scala. (January 15, Article)

Developers split on open sourcing Java

Now that Oracle is absorbing Sun Microsystems, there mixed views on what should come of the Java Community Process (JCP). While some say Oracle should become the new steward of Java and keep the JCP much as it was, others argue that it may be time to open-source this widespread language. (November 24, Article)

Dependency Injection in Java EE 6 - Part 1

Reza Rahman explores the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6. (November 2, Article)

SAML: It's Not just for Web services

SAML is an XML-based standard for exchanging authentication and authorization data between security domains. The single most important problem that SAML was created to solve is the Web browser Single Sign-On problem. Many organizations are debating whether to stay with version 1.1 or move to 2.0. This article makes observations about both options. (September 28, Article)

Programming is Also Teaching Your Team

Joe Ottinger takes a look at how people learn, and applies it to the practice of programming. He notes that understanding how people learn is an essential part of working in a programming team. (September 22, Article)

Can Java EE Deliver The Asynchronous Web?

Stephen Maryka gave us an article about the Asynchronous Web and posed a number of questions that get examined like an approach to delivering Asynchronous Web capabilities through extensions to existing Java EE technologies. (July 14, Article)

JSF Flex

JavaServer Faces Flex goal is to provide users capability in creating standard Flex components, part of flexSDK which is open sourced through MPL license, as normal JSF components. This article by Ji Hoon Kim will provide an overview of creating a simple multilingual JSF page consisting of JSF Flex tags. (June 29, Article)

The Rules of SOA - A Road to a Successful SOA Implementation

In this session Jeff explores the key characteristics of successful SOA projects. He covers some of the patterns, and anti-patterns, tool sets, and strategies that he himself learned the hard way. Last, he provides a strategy and blueprint for achieving a high likelihood of success in your SOA project. (June 23, Tech Talk)

Ari Zilka Talks About Terracotta 3.1

Ari Zilka, CTO of Terracotta, Inc., talks about the new features in Terracotta 3.1, announced during JavaOne and available now. (June 15, Tech Talk)

Enterprise Application Integration, and Spring

In this Tech Talk, Josh Long explores an integration challenge using Spring Integration and walks through the implementation, employing and expanding on the basic patterns of Enterprise Application Integration to tie together components into a function integration solution, and then demonstrates how Spring Integration helps address the integration requirements. (June 15, Tech Talk)

Google Web Toolkit: An Introduction

In this Tech Talk, David Geary teaches you: The basics of Google Web Toolkit; How to implement Ajax-enabled applications in Java; Internationalization; Hooking into the browser history mechanism; Remote procedure calls. (June 4, Tech Talk)

Just Enough Early Architecture to Guide Development

Jon Kern discusses the best architecture/technical solutions and ensure that they are repeated by all developers. By tackling the architecture up-front in a serial manner, subsequent parallel development will be much more manageable and predictable. (May 28, Tech Talk)

Productive Programmer: On the Lam from the Furniture Police

This keynote describes the frustrations of modern knowledge workers in their quest to actually get some work done, and solutions for how to guard yourself against all those distractions. Neal Ford talks about environments, coding, acceleration, automation, and avoiding repetition as ways to defeat the misguided attempts to sap your ability to produce good work. (May 26, Tech Talk)

Auto-Scaling Your Existing Web Application

Gil demonstrates how new, aggressive uses of already abundant compute capacity by common applications offer competitive value for application designers. (May 21, Tech Talk)

Automating Hibernate Mapping and Queries For Java Web Development

Chris Keene introduces WaveMaker as a new way to automate the ability to generate Hibernate classes in order to more quickly bring OR mapping into an application. (May 19, Article)

Free Book PDF Download: Mastering EJB Third Edition

Mastering EJB was one of the original and most influential EJB books in the industry. Mastering EJB III now returns with two new expert co-authors, updated for EJB 2.1 and 30% new chapters including security, integration, best practices, open source, and more.
(Book PDF Download)

Application Server Matrix

The Application Server Matrix is a detailed listing of J2EE vendors and their application server products, with information on latest version numbers, J2EE spec support and licensing, pricing, platform support, and links to product downloads and reviews.
(Application Server Comparison Matrix)

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
Java Solutions
All Content Copyright ©2007 TheServerSide Privacy Policy
Site Map