
|
|
|||
Assertion Extensions for JUnitBy Tony Morris2005-05-05
AlphaWorks Package Allows you to Perform Unit Testing with Complex Assertions More Easily JUnit lets you test software code units by making assertions that the intended requirements are met, but these assertions are limited to primitive operations. IBM Software Engineer Tony Morris fills the gap by introducing Assertion Extensions for JUnit, which provides a set of complex assertions that execute within the JUnit framework. Follow along as the author shows you how using this new package from alphaWorks can increase the reliability and robustness of your Java™ software. The popular JUnit automated unit-testing framework gives you a way to test software code units by making assertions that your code meets the intended requirements. However, these assertions are limited to primitive operations, such as "assert equal on two variables" and "assert not null on a reference variable." The primitive JUnit assertions are useful, but they don't represent the many complex assertion abilities you need in real-world software unit-testing scenarios. Assertion Extensions for JUnit (JUnitX), an extensions package for the JUnit framework, is available for download from alphaWorks (see Resources). It provides the required implementation of many common complex assertions. Rather than write a complex JUnit test case for an assertion, you can call a JUnitX method to make that assertion from the same context -- with no additional setup. JUnitX also asserts that it functions as documented by including its own JUnit self-test suite. This reassures you that JUnitX is making its assertion according to the JUnitX documentation; if a unit test fails, you know it's the software code unit that has failed, not the JUnitX test implementation asserting a false failure. A typical scenario in which JUnitX would be beneficial involves the contracts set out by the java.lang.Object class's equals(Object) and hashCode() methods. You're often required to adhere to these contracts in the classes you develop. Using JUnit to make the assertion that you've adhered to them would require you to develop complex unit-test cases, which are prone to error. In contrast, making the assertions using JUnitX is as simple as creating a factory implementation that returns instances of your class and calling the JUnitX assertEqualsContract and assertHashCodeContract methods from your unit-test case. Tutorial Pages: » AlphaWorks Package Allows you to Perform Unit Testing with Complex Assertions More Easily » Getting Started with JUnitX » Use Case Scenario » Conclusion » Resources First published by IBM DeveloperWorks |
||||
| About the NetVisits, Inc Network | Write For Us | Advertise Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy. |
Visit other NetVisits, Inc. sites: |