Browse DevX
Sign up for e-mail newsletters from DevX


Execute EJB JUnit Tests in Your Deployed Apps

Extend the life of your JUnit tests by enabling them to be executed inside a real deployed J2EE app, not just on developer PCs.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

esting is an integral part of any development process. JUnit, an open-source, regression-testing framework written by Erich Gamma and Kent Beck is a popular tool for building Java unit tests. JUnit provides a basic framework for developers to structure tests and test suites (test collections). Once in place, developers can use these tests to regression test either locally on their workstations or during the build and deployment processes.

Sometimes, however, tests are developed in a way that precludes them from being executed against a real deployed application. They run well enough inside local IDEs against test servers, but they won't run in user acceptance test (UAT) or production-like environments. Test developers can end up making assumptions about the environment that limit the effectiveness and scope of their regression tests:

  • Tests rely on direct access to the DBMS.
  • JUnit test runner classes cannot be executed on the target deployment box because the box is inaccessible.
  • JUnit test runners can be used, but tests rely on access to application resources such as datasources that may not work outside the container.
  • Tests are not designed cleanly and leave unwanted data debris in the database after execution.

All of these contributing factors prevent tests from being automated. However, all is not lost. You can enable your tests to be executed without a lot of code refactoring or retooling. By building a simple JUnit test execution service that runs inside your application, you can support in container test execution via command-line, over HTTP, or even expose test execution as a Web service. Rather than running tests standalone using JUnit or IDE tools, you can execute them inside a deployed application.

An EJB-Backed Test Service

Think of your test service as any other application business service. It should provide a simple, securable mechanism for executing JUnit tests and communicating the results. By using a stateless session bean to implement your service, you can leverage the transaction semantics of the container to tear down your data once your tests are done. That way, you don't have to worry about test data messing up your system.

My JUnit tests run fine in development, but they won't run standalone against a real deployment.

Learn how a simple EJB JUnit test service can facilitate test execution in real deployment environments, not just on developer PCs.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date