A Tutorial on JUnit in Eclipse

A Tutorial on JUnit in Eclipse

Table of contents
 (一)System Environment:

  1. J2SE Development Kit version 1.5 (abbr. JDK 1.5)
  2. Eclipse IDE version 3.2 (abbr. Eclipse 3.2)
  3. Windows OS or Linux OS

 (二)Prerequisite:

  1. Your Computer must be online.
  2. Download the follow Packages
    ..Download JUnit version 4.1, here
    ..Download FunctionalJ version 0.8 JDK 1.5, here
    ..Download log4j version 1.2.14, here

 (三)Goal:

  1. JUnit is a Java Test Framework, with which Java classes can originally be tested automated. That is a short introduction to JUnit.
  2. You can get this codes from Google Code Hosting:
    svn co http://cnjava.googlecode.com/svn/trunk/testing/daoxi_junit/

 (四)Solution:

  1. Create Eclipse Java Project daoxi_junit
  2. Add Packages to Project daoxi_junit
    ..Add JUnit junit-4.1.jar to Project daoxi_junit
    ..Add FunctionalJ functionalj-0.8-jdk15.jar and cglib-nodep-2.1_3.jar to Project daoxi_junit
    ..Add JUnit log4j-1.2.14.jar to Project daoxi_junit
  3. Process Class Daoxi
    ..Add Package com.hhtong.examples.junit.step01
    ..Add Class Daoxi
    ..Add Class Daoxi Code
    ..Run Class Daoxi as Java Application
  4. Process Class DaoxiTest
    ..Add Package com.hhtong.examples.junit.step01
    ..Add Class DaoxiTest as JUnit Test Case
    ..Add Class DaoxiTest Code
    ..Run Class DaoxiTest as Java Application
    ..Run Class DaoxiTest as JUnit Test
  5. All other steps are as (3) and (4).

 (五)Video:

  •  

 (六)Attention:

  • Note Project "daoxi_junit" to the test class methods
    ..The name must begin with “test”
    ..You may not have parameters
    ..You must be allowed "public" and not "static" to be
    See German References 2
  • Note JUnit version 4.1
    ..Es exists not the class junit.swingui.TestRunner. It appears that they've dropped that class.
    See English References 3

 (七)References:

  1. http://functionalj.sourceforge.net/ch01.html
  2. http://www.torsten-horn.de/techdocs/java-junit.htm
  3. http://forum.java.sun.com/thread.jspa?threadID=762667&messageID=4351924

 (八)Command List:

  •  

 (九)Download File pdf:

  •  

About this entry