|  |
Assertion Extensions for JUnit
A set of extensions for JUnit that enable complex assertion abilities.
Date Posted: February 25, 2005
|
|
 |
 |
|
What are Assertion Extensions for JUnit?
Assertion Extensions for JUnit (JUnitX) is a set of assertion extensions that attempts to cover the most common test scenarios in JavaTM software development. This includes method contracts up to and including J2SE 1.5.0 and various other common features. JUnitX asserts that a success or failure assertion result is correct by including its own self-test suite with greater than 90% code coverage. The JUnitX package includes source code, unit test source code, an HTML code style report (100% adherence), an HTML unit test report (100% success), an HTML unit test coverage report (greater than 90% coverage), Javadoc documentation (100% exposed API), an HTML FAQ document, and an HTML README document.
JUnit is a testing framework written by Erich Gamma and Kent Beck. It is used by software developers to express their requirements in source code, and it automatically asserts those requirements when it is necessary to regression-test their software. JUnit is open source and is available under the CPL 1.0 license.
Although JUnit is a framework for testing, it does not provide the robustness required to make assertions on software other than in the most trivial sense. For example, JUnit provides assertion operations such as assert true or assert equal to, but it does not allow the making of an assertion such as assert the java.lang.Object equals and hashCode method contracts. In order to make this last assertion, the developer typically must write the source code to determine if each method contract has been met and then use JUnit to assert true that the contract is met using the source code just written. The problem with this approach is that the code for determining whether the method contract is met is relatively complex and it is just as error-prone as meeting the method contract itself. A success or failure of the assertion is not reliable. For example, a failure might indicate that the test source code is defective or that the source code under test is defective. A successful result might indicate that the test source code and the source code under test are both defective.
The source code, including test harness, will be shipped with the software in order to increase its effectiveness.
How does it work? JUnitX has been designed to meet several objectives. The most important objective was to ensure that the assertions it makes are correct; therefore, unit testing is emphasized. Another objective was to provide an easily-extended design. This design was achieved by separating each concern related to each assertion; no public APIs are exposed that are tied to an implementation. This separation means that all client software deals only with the operation signatures through the API and not how the operations are implemented. This separation also benefits the JUnitX user because documentation is not cluttered with unnecessary, implementation-specific documentation. The user need only know what the assertion does, not how it does it. In addition, this design means that future enhancements to JUnitX can be made to the implementation of the assertions while reverse compatibility is maintained, since the user has never been exposed to the implementation. This benefit was achieved by making heavy use of Java interfaces and factory methods to return hidden implementations of these interfaces.
Users can make use of the JUnitX assertions in a JUnit test environment by using the class junitx.framework.Assert. Use of this class is intended to replace the use of the JUnit class junit.framework.Assert. Everything that is available in the JUnit Assert class is also available in the JUnitX Assert class through inheritance. This inheritance allows easy adaptation of existing test source code to JUnitX.
To see an example user scenario, refer to the complementary article on developerWorks. For further documentation on the JUnitX APIs for making assertions, refer to the Javadoc included in the JUnitX package. To use JUnitX in a JUnit test environment, it is recommended that the junitx.framework.Assert class be used; please refer to its Javadoc for a list of APIs.
|
|
 |

|  | About the technology author(s):
Tony Morris is a software engineer at IBM Tivoli's Lab, located on the Gold Coast, Australia. He works with Java security components, such as the Java Cryptography Extension (JCE), and develops tools for digital certificate management. Mr. Morris has seven years of experience programming on the Java platform and is a part-time lecturer for the School of Information Technology at Griffith University, Gold Coast, Australia. He holds a Bachelor of Information Technology degree from Griffith University and is a Sun Certified Programmer and Sun Certified Developer for the Java 2 Platform.
|
| |
|
| |
|