Professional Documents
Culture Documents
JUnit 4
2
Characteristics of a good Unit Test
¾ Isolated
Æ Test Single Unit
¾ Fast
Æ Don’t waste the developer’s time
3
Characteristics of a good Unit Test
¾ Self Contained
Æ Doesn’t rely on external resources that could fail
¾ Independent
Æ Doesn’t depend on any other tests
4
Characteristics of a good Unit Test
¾ Maintainable
Æ Treat just like any other code
¾ Well documented
5
Integration Testing
6
Unit Testing with JUnit 3
7
Unit Testing with JUnit 3
HelloWorld classUnderTest;
8
Extending JUnit 3
¾ Extend TestCase
9
Extending JUnit 3 – Example
XMLUnit
public class MyXMLTestCase extends XMLTestCase {
. . .
. . .
assertXMLEqual(myControlXML, myTestXML);
assertXMLNotEqual(myControlXML, myTestXML);
10
Advantages of JUnit 3
11
Changes in JUnit 4
¾ New Functionality
Æ @BeforeClass, @AfterClass
Æ @Ignore
12
Unit Testing with JUnit 4
static import org.junit.Assert.*;
HelloWorld classUnderTest;
13
Extending JUnit 4
14
Filters and Sorters
¾ Filters
Æ Filter Tests based on custom requirements
¾ Sorters
Æ Allow for custom sorting of tests
Æ Should not be used for the correctness of tests
15
Advantages of JUnit 4
16
Development at ImageTech Systems
17
The Problem with Integration Testing
18
What We Needed: Data-Driven Tests
19
A Quick Aside: Testing Patterns
¾ Examples
Æ The Simple Pass/Fail Test Pattern
Æ The Performance Test Pattern
Æ The Data-Driven Test Pattern
20
The First Solution
21
The Second Solution: Parameterized
22
The Final Solution:
XMLParametrizedRunner
¾ Custom test runner
23
XML File Format
<tests>
<test>
</test>
</tests>
24
XML File Format
¾ JavaBean Parameters:
<bean class=“someClass”>
<property name=“example” value=“Something” />
</bean>
25
XMLParamterizedRunner
implementation
¾ Implements Runner by extending internal
JUnit TestClassRunner
26
Jakarta Commons Digester
27
The JUnit 4 Extensions Project
¾ Additional Annotations
Æ @Prerequisite
Æ @Category
28
XMLParameterizedRunner - Future
Plans
¾ Continue to develop the XML format
29
JUnitExt - Future Plans
30
Resources and Links
¾ JUnit
Æ http://www.junit.org
Æ http://junit.sourceforge.net
31
Resources and Links
¾ XMLUnit
Æ http://xmlunit.sourceforge.net/
32
Resources and Links
¾ Robots on Wikipedia
Æ http://en.wikipedia.org/wiki/R._Daneel_Olivaw
Æ http://en.wikipedia.org/wiki/Marvin_the_Paranoid_Android
Æ http://en.wikipedia.org/wiki/Johnny_5
Æ http://en.wikipedia.org/wiki/HAL9000
33