Software Construction: Unit Testing
Software Construction: Unit Testing
Unit Testing
Christoph Denzler / Martin Kropp
University of Applied Sciences Northwestern Switzerland
Institute for Mobile and Distributed Systems
Learning Target
You
understand and can explain the importance of
testing
can describe the basic concepts of the JUnit
testing tool
can use and configure JUnit
can organize and write simple tests
That means
1. There must be well specified requirements to
test against (expected results)
2. Testing is comparing actual results to expected
results
1991: The Patriot Missile failure, in Dharan, Saudi Arabia, on February 25, 1991
which resulted in 28 deaths, is ultimately attributable to poor handling of rounding
errors.
1991: The sinking of the Sleipner A offshore platform in Gandsfjorden near
Stavanger, Norway, on August 23, 1991, resulted in a loss of nearly one billion
dollars. It was found to be the result of inaccurate finite element analysis.
1996: The explosion of the Ariane 5 rocket just after lift-off on its maiden voyage
off French Guiana, on June 4, 1996, was ultimately the consequence of a simple
overflow.
1999: NASA’s Mars lander, September 1999, crashed due to a units integration
fault—over $50 million US !
2005: Arbeitslosengeld II = ALG-II in Germany:writing 9 digit bank codes left-
aligned in 10 digit fields leads to adding a zero at the end and wrong bank codes.
2010: Year 2010 bug on German bankcards (Jan 4 2010): It showed up to be a
software defect due to incorrect year handling.
More on http://www5.in.tum.de/~huckle/bugse.html
classes
methods
system
integration
component
unit
Accessibility
stress
white box black box
performance
reliability
usability
robustness
functionality
Target
UnitTesting (Part1), FS2010 IMVS, Ch. Denzler/M. Kropp 13
The Testing Process
Test Test
Test case Test data
results report
Use Asserts by
using the prefixed syntax
Assert.assertEquals()
importing statically the Assert class
import static org.unit.Assert.assertEquals
There are several assertions
assertEquals()
assertEquals([String message], expected, actual)
assertEquals([String message], expected, actual,
tolerance)
assertNull(), assertNotNull(), assertSame(), assertNotSame(),
assertTrue(), assertFalse(), fail()