Home > Articles > Programming

The Best Java Open-Source Tools

Java developers have a plethora of tools and libraries available for free on the Internet. Expend some energy learning how to use them, and you can leverage their strengths to produce higher-quality software more rapidly.

The open source software (OSS) community is an anarchist's dream—no governing body, no ownership of property, freedom in speech and action. The community is practically an organized religion, with gurus around which the devoted eagerly gather. We also have temples—GNU, Apache, Jakarta (the Apache sect responsible for Java), SourceForge (home of a multidenominational congregation), JBoss, ExoLab, JUnit (a small deviant sect that's growing rapidly). We even have our fair share of religious bigots—witness the attacks on followers of the church of Microsoft.

NOTE

GNU is actually all about free software, not open source software.

This article is part of a project to document and connect best practices in Java development with the most popular open source tools and libraries. Eventually this will blossom into a book and a web site. For this article, however, the idea is just to describe the tools that all Java developers need to know.

JUnit and Friends

JUnit was conceived as part of extreme programming, and has now been ported to just about every platform for which a programmer exists. JUnit allows you to write and execute unit tests rapidly. These two features—low energy costs and tests that run fast—were primary factors in JUnit's evolution. Authors Kent Beck and Erich Gamma knew that if it was hard and slow, nobody would use it.

JUnit itself only provides a framework against which to write simple tests. The concept is simple: For each Class you write, you also write a TestClass that contains all the tests for that class. The TestClass is a TestCase; that is, you must extend TestCase to create TestClass. It's possible to have multiple test cases for each class you write, but usually it's unnecessary. Test cases are gathered into test suites, and the whole thing runs at the press of a button.

When I'm writing tests, I'm constantly switching backward and forward between tests and code. I run tests multiple times each minute, making small changes between runs. If writing tests took more time, I probably wouldn't do it. I can write tests without slowing down—in fact, it feels like I'm going really fast. The unit tests improve the quality of my code, which in turn increases my productivity.

JUnit has to be kept simple, so the creators haven't added the many features that developers have requested. Instead, they built the core framework so that it was easy to extend. Now developers choose just the libraries they need.

NOTE

J2EE developers: All of the JUnit tools and extensions can be located through the JUnit web site.

Extensions

JUnit-Addons is the first of JUnit's friends that we'll discuss. It was developed to fill a number of important gaps in JUnit's base feature set. Two of its features are helpful enough to be used almost every day:

  • Private parts. While it's always a good idea to treat the class you're testing as a black box, sometimes this is impossible, particularly if you're doing test-driven development. The facilities offered by JUnit-Addons are sufficient even for the most demanding of needs. It offers a simple technique for accessing private attributes and methods, even on the class (static).

  • Arrays. When you're comparing two arrays for equality in JUnit, you're actually only comparing the array references. JUnit-Addons extends JUnit to include the ability to iterate through the arrays, comparing elements. Although arrays have nearly been replaced by collections, there are still some places where it's good to use an array—particularly if you want to create an array initializer. In these places, you need JUnit-Addons—otherwise, your arrays go untested.

GUIs

While many enlightened developers follow the J2EE path, some still find time for the simpler pleasures of Swing.

NOTE

Industry rumor: Microsoft slipped one of their designers into Sun to gather industrial espionage. He was nearly caught, but managed to convince people that he was part of the Swing team by designing a layout controller. While he was at it, he threw in some industrial sabotage, and the result is the GridBagController.

Still oblivious to the damage, Sun later invited him back, and he designed the SpringLayout in JDK1.4.

Swing

If you write GUIs, you have to test them. To test Swing GUIs, you need jfcUnit. jfcUnit is a wonderful library that helps you gain complete access to your GUI and control it using software robots that can press buttons, move the mouse, and press keys (all simulated, of course).

jfcUnit allows you to code your GUI driver in Java. There are significant benefits to this approach versus recording human/computer interaction sessions—especially if you're doing test-driven-development or extreme programming. If you're writing your code test-first, you'll have problems using an interaction recorder, because there's no GUI to record until you've written the tests. In this paradigm, you have no choice but to code the GUI tests by hand.

Mock Objects

Mock Objects are a way of testing complex environmental objects and having them behave the way you want. You want to test the way your code interfaces with a database. Easy, right? But what about testing your code's behavior when the database goes down? A good solution would be to create a mock database, using Mock Objects. The idea is that you create something that conforms to the database's interface, setting it up in any way you want, which includes responding as if the database has gone down. You can forget about rolling back data; just make the mock object return the necessary figures, even allowing it to calculate them if you want.

At the Mock Objects web site, you can download a library of mocks for most of Java's complicated interfaces, such as servlets, SQL, and I/O. There are also links to a few tools that will allow you to generate interfaces so you can mock out your host integration, or resolve other difficult problems.

J2EE

I can't very well talk about Java without talking about J2EE—there are no hard figures on this, but I'd guess that a very large portion of Java developers are in the J2EE space.

HTML

Of course, the enlightened use HTML for all their human/computer interaction needs. It doesn't matter how you generate it—servlets, JSP, Struts, XML/XSLT, whatever—you're still going to have to test that front end. Common wisdom has it that HTTPUnit is fit for this task—but I disagree. HTTPUnit is a powerful and useful tool, but if you're just going to test HTML forms then I recommend Canoo WebTest.

WebTest allows you to write your tests as an ANT script. (If you don't know what ANT is, scan ahead and read that section.) It includes a custom task to parse the test script and run it. The test script is in XML, and is extremely simple to write. A tag called invoke takes a URL as its parameter. This is a simple call to the web server. You can use tags such as verifyTitle, setInputField, getInputField, clickButton, and so on. It's all intuitively simple, and it works well.

Servlets, Enterprise Java Beans (EJBs), Etc.

Of course, no coverage of J2EE testing tools would be complete without discussing Cactus. Cactus, from the Apache Jakarta tribe, is probably the most well-known JUnit extension in the J2EE world.

Cactus allows you to test your code's interaction with its container. (Actually, it allows much more than this, but this is what makes it most useful.) It lets you check whether the container does what you expect it to do, and whether your code is a well-behaved member of the container's application family. It does this by running as a servlet within your container of choice, so it works well with Tomcat, JBoss, WebSphere, WebLogic, whatever—it doesn't care. It allows you to test servlets and/or EJBs.

JSPs

I'm not going to talk about testing JSPs—there shouldn't be anything in your JSP that needs testing. It generates HTML, so test that with WebTest or something similar.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020