Using JUnit from Eclipse - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Using JUnit from Eclipse

Description:

Using JUnit from Eclipse Notes Using JUnit from Eclipse Summary 1 JDT Setting Goal: make the individual setting a little easier Some base setting to ease the ... – PowerPoint PPT presentation

Number of Views:59
Avg rating:3.0/5.0
Slides: 29
Provided by: dogbertM8
Category:
Tags: eclipse | junit | using

less

Transcript and Presenter's Notes

Title: Using JUnit from Eclipse


1
Using JUnit from Eclipse
  • Notes

2
Using 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

3
Using 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

4
JDT Setting
5
JDT SettingOpen Preferences
  • MenuWindow-gtPreferences

6
JDT 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

7
JDT SettingSetting Complete
added
8
Individual Project Setting
9
Individual Project SettingOpen ltProjectgt
Properties
Select Project (e.g. PetStore) -gt context menu
(right click)
Properties
10
Individual Project SettingSet Library Path
11
Individual Project SettingSet Source Path 1
12
Individual Project SettingSet Source Path 2
13
Project creation tip
14
Project creation tipPreparing separate test
folders
Context Menu (right click) -gt New -gt
Project
15
Project creation tipPreparing separate test
folders
16
Project creation tipPreparing separate test
folders
add src and test by doing this twice
When they ask for output folder as bin say "yes"
17
Project 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.
18
Using "JUnit" Wizard
19
Using "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"
20
Using "JUnit Wizard"Start Wizard
  • Select a java file
  • From context menu (right click)
  • New
  • Other

21
Using "JUnit Wizard"Create TestCase
  • Click on by Java
  • Select JUnit below it
  • Select TestCase to create TestCase for Pet.java
  • And push Next

22
Using "JUnit Wizard"Set it to "test" folder
  • Change Source Folder to "test" by Browse

23
Using "JUnit Wizard"Select which method to test
  • Select the methods to create test methods
  • Then click Finish

24
Using "JUnit Wizard"Create a test
Write in your test
Write in your test
Write in your test
Test Program Template is created
25
Run JUnit from Eclipse
26
Run 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

27
Run 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)

28
Run JUnit from EclipseWhen it seems it is not
working...
  • Look at the bottom of the Package Explorer and
    just click JUnit tab
Write a Comment
User Comments (0)
About PowerShow.com