Unit Testing: Australian Development Centre Brisbane, Australia
Unit Testing: Australian Development Centre Brisbane, Australia
Aims
Unit Testing vs Traditional Testing Benefits of Unit Testing Introduction to xUnit (using JUnit) frameworks Advanced Unit Testing Strategies
Traditional Testing
Test the system as a whole Individual components rarely tested Errors go undetected Isolation of errors difficult to track down
Unit Testing
Each part tested individually All components tested at least once Errors picked up earlier Scope is smaller, easier to fix errors
Unit Tests
Simple Standalone Classes High Level Classes Database based Classes Integrated Framework Classes
JUnit (www.junit.org)
Java-based unit testing framework Elegantly simple Easy to write unit tests Easy to manage unit tests Open source = Free! Mature Framework De facto java standard Ant integration Generic testing framework
EJB Components
Assert
<Test> run(TestResult)
TestSuite run(TestResult)
JUnit is Easy
public void testInvalidPersonName() { person.setFirstName(null); person.setLastName(Smith); try { personService.createPerson(person); fail(An invalid person name should be thrown); } catch (InvalidPersonName ipn) { // Exception expected } }
Executed line
Conclusion
Unit testing adds enormous value to software development JUnit makes testing java programs easy Advanced Unit Testing Concepts
Questions?