| Free tutorials for Java, Eclipse and Web programming |
Version 1.2
Copyright © 2007 - 2010 Lars Vogel
05.04.2010
| Revision History | ||
|---|---|---|
| Revision 0.1-0.5 | 03.09.2007 | Lars Vogel |
| JUnit description | ||
| Revision 0.6 - 1.2 | 10.05.2008 - 05.04.2010 | Lars Vogel |
| bugfixes and enhancements | ||
Table of Contents
A unit test is a piece of code written by a developer that tests a specific functionality in the code which is tested. Unit tests can ensure that functionality is working and can be used to validate that this functionality still works after code changes.
Unit testing uses also mocking of objects. To learn more about mock frameworks please see EasyMock Tutorial
JUnit 4.x is a test framework which uses annotation to identify the test methods. JUnit assumes is that the all test can be performed in an arbitrary order. Therefore tests should not depend other tests. To write a test with JUnit
Annotate a method with @org.JUnit.Test
Use a method provides by JUnit to check the expected result of the code execution versus the actual result
Download JUnit4.x.jar from the JUnit website . The download contains a "junit-4.*.jar" which is the JUnit library. To make JUnit available in your Java project you have to add the the JUnit library file to your Java classpath. See Eclipse IDE Tutorial to learn how to do this in Eclipse.