Title: Using JUnit from Eclipse
1Using JUnit from Eclipse
2Using JUnit from EclipseSummary 1
- JDT Setting
- Goal make the individual setting a little easier
- Some base setting to ease the individual project
settings - Individual Project Setting
- Goal set up the project to enable JUnit
- Necessary setting for individual projects when
you create one
- Project Creation Tip
- Goal organize folders with all the tests added
- A tip to create a separate test folder but with
same java package - TestCase should be in the same Java package so
that it can test the program without "visibility"
problems - But we want to organize them so that we can see
clearly that one is a test and one is the code
3Using JUnit from EclipseSummary 1
- Using JUnit Wizard
- Goal ease the task of creating test case
- There's a wizard that helps you create a TestCase
and TestSuite from some code you have created. - Run JUnit from Eclipse
- Goal use integrated environment of Eclipse to
run the test - In Eclipse, we can code, test, run,
debug!!
- Further Information
- http//www.junit.org/
- Look under articles to see usage descriptions in
practice - For the team we will do pair program to
understand how we will proceed
4JDT Setting
5JDT SettingOpen Preferences
6JDT SettingWhat to set
- Use File Button to set following variables
- JUnit Library (JUNIT_LIB)
- ECLIPSE_HOME\plugins\org.junit_3.8.1\junit.jar
- JUnit Source (JUNIT_SRC)
- ECLIPSE_HOME\plugins\org.eclipse.jdt.source_2.1.3\
src\org.junit_3.8.1\junitsrc.zip
7JDT SettingSetting Complete
added
8Individual Project Setting
9Individual Project SettingOpen ltProjectgt
Properties
Select Project (e.g. PetStore) -gt context menu
(right click)
Properties
10Individual Project SettingSet Library Path
11Individual Project SettingSet Source Path 1
12Individual Project SettingSet Source Path 2
13Project creation tip
14Project creation tipPreparing separate test
folders
Context Menu (right click) -gt New -gt
Project
15Project creation tipPreparing separate test
folders
16Project creation tipPreparing separate test
folders
add src and test by doing this twice
When they ask for output folder as bin say "yes"
17Project creation tipPreparing separate test
folders
If there's some folders left out, just do Add
Folder and add it again. It should look like
left (with two folder if you added two.)
If you answered "yes" for the output directory
being bin it should say something like left.
18Using "JUnit" Wizard
19Using "JUnit Wizard"
- Use this wizard
- when you first create a class
- or when you already have classes
- Example
- Pet.java
public class Pet public Pet()
public String bow() return "Bow"
20Using "JUnit Wizard"Start Wizard
- Select a java file
- From context menu (right click)
- New
- Other
21Using "JUnit Wizard"Create TestCase
- Click on by Java
- Select JUnit below it
- Select TestCase to create TestCase for Pet.java
- And push Next
22Using "JUnit Wizard"Set it to "test" folder
- Change Source Folder to "test" by Browse
23Using "JUnit Wizard"Select which method to test
- Select the methods to create test methods
- Then click Finish
24Using "JUnit Wizard"Create a test
Write in your test
Write in your test
Write in your test
Test Program Template is created
25Run JUnit from Eclipse
26Run JUnit from EclipseRunning the Test
- Select the TestCase class (or TestSuite class)
- Then, just do
- Either from Run icon or from Run menu
- Run As
- JUnit Test
27Run JUnit from EclipseGetting the Results
- Window should appear over the Package Explorer
like left - There will be information about the test coming
out - Here 2 tests were run successfully (2/2 and all
green)
28Run JUnit from EclipseWhen it seems it is not
working...
- Look at the bottom of the Package Explorer and
just click JUnit tab