Introduction To Unit Testing SE 2 Tutorial: Herman Lee May 26, 2008
Introduction To Unit Testing SE 2 Tutorial: Herman Lee May 26, 2008
Based on tutorial slides prepared by Thiago Bartolomei SE 3 lecture slides prepared by Paulo Alencar
Testing Stages
Unit testing
Testing of individual components
Integration testing
Testing to expose problems arising from the combination of components
System testing
Testing the complete system prior to delivery
Acceptance testing
Testing by users to check that the system satisfies requirements. Sometimes called alpha testing
Unit testing
Set of test cases targeting a single module and organized in test suites Strongly encouraged by the agile community
That's it!
JUnit 4
Test Cases
No longer have to extend TestCase Test methods annotated with @org.junit.Test setUp/tearDown annotated with @Before/@After Assertions statically accessed from Assert
Test Suites
No longer extend TestSuite Annotated with RunWith and Suite
Example
Source: http://www.devx.com/Java/Article/31983/0/page/1
Source: http://www.devx.com/Java/Article/31983/0/page/2
DEMO in Eclipse
Or in a test package:
pack.TheClass, pack.test.TheClassTest
Also, in an Eclipse project, you can have different source folders with the same package:
src/pack.TheClass, test/pack.TheClassTest Advantage you have protected access to the class
JUnit
http://www.junit.org JUnit 3 vs 4
http://www.devx.com/Java/Article/31983