Overview of Eclipse Lectures

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
T ESTING WITH J UNIT IN E CLIPSE Farzana Rahman. I NTRODUCTION The class that you will want to test is created first so that Eclipse will be able to find.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
Georgia Institute of Technology DrJava Appendix A Barb Ericson Georgia Institute of Technology May 2006.
MT311 Tutorial Li Tak Sing( 李德成 ). Uploading your work You need to upload your work for tutorials and assignments at the following site:
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Fall 2007CS 2251 Programming Tools Eclipse JUnit Testing make and ant.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Java Development Tools project.
1 CSC/ECE 517 Fall 2010 Lec. 2 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Debugging 5.Testing.
Programming Tools Eclipse JUnit Testing make and ant.
Eclipse IDE. 2 IDE Overview An IDE is an Interactive Development Environment Different IDEs meet different needs BlueJ and DrJava are designed as teaching.
03 Using Eclipse. 2 IDE Overview An IDE is an Interactive Development Environment Different IDEs meet different needs BlueJ and DrJava are designed as.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
INF 111 / CSE 121 Discussion Session Week 2 - Fall 2007 Instructor: Michele Rousseau TA: Rosalva Gallardo.
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Author: Loh Jianxiong Christopher Editors: Chua Jie Sheng, Li Mengran, Peh Shao Hong, Oo Theong Siang.
Workbench Overview Dwight Deugo Nesa Matic
CSC 216/001 Lecture 4. Unit Testing  Why is it called “unit” testing?  When should tests be written?  Before the code for a class is written.  After.
CPSC1301 Computer Science 1 Overview of Dr. Java.
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
Debugging Dwight Deugo Nesa Matic
Debugging. 2 © 2003, Espirity Inc. Module Road Map 1.Eclipse Debugging  Debug Perspective  Debug Session  Breakpoint  Debug Views  Breakpoint Types.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
9/2/ CS171 -Math & Computer Science Department at Emory University.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger.
JUnit Dwight Deugo Nesa Matic
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
JUnit Dwight Deugo Nesa Matic
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
A tool for test-driven development
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting.
Object-Oriented Programming (Java). 2 Topics Covered Today Unit 1.1 Java Applications –1.1.8 Debugging –1.1.9 Debugging with Eclipse.
Eclipse Project. Installing Visit to download a copy for your home computerhttp:// –Get Release version 3.0 (or.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
1 CSC 216 Lecture 3. 2 Unit Testing  The most basic kind of testing is called unit testing  Why is it called “unit” testing?  When should tests be.
JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
TOOLS FOR DESIGN AND DEVELOPMENT ENVIRONMENTS. Case study - ECLIPSE Lecture notes 5.
15 Copyright © 2004, Oracle. All rights reserved. Debugging Triggers.
Software Design– Unit Testing SIMPLE PRIMER ON Junit Junit is a free simple library that is added to Eclipse to all automated unit tests. The first step,
Editing and Debugging Mumps with VistA and the Eclipse IDE Joel L. Ivey, Ph.D. Dept. of Veteran Affairs OI&T, Veterans Health IT Infrastructure & Security.
Java IDE Dwight Deugo Nesa Matic
1 Using an Integrated Development Environment. Integrated Development Environments An Integrated Development Environment, or IDE, permits you to edit,
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Debugging with Eclipse
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Eclipse.
Software Construction Lab 10 Unit Testing with JUnit
Module Road Map Refactoring Why Refactoring? Examples
Introduction to Eclipse
Dept of Computer Science University of Maryland College Park
ATS Application Programming: Java Programming
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Debugging Dwight Deugo
An Automated Testing Framework
Important terms Black-box testing White-box testing Regression testing
Eclipse 20-Sep-18.
Important terms Black-box testing White-box testing Regression testing
Debugging with Eclipse
Overview of Eclipse Lectures
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
Introduction to JUnit IT323 – Software Engineering II
Debugging Dwight Deugo
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Eclipse JUnit Testing make and ant
Joel Adams and Jeremy Frens Calvin College
JUnit Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from the Eclipse 3.0 and.
Debugging with Eclipse
Workshop for Programming And Systems Management Teachers
Presentation transcript:

Overview of Eclipse Lectures Installing and Running Building and Running Java Classes Debugging Testing with JUnit Refactoring Version Control with CVS “Lecture 0” Lecture 2 Let’s begin with an overview of Eclipse. Lecture 3 CSC/ECE 517 Fall 2009 Lec. 2

Module Road Map Debugging Debug Perspective Debug Session Breakpoint Overview Installing and Running Building and Running Java Classes Debugging Debug Perspective Debug Session Breakpoint Debug Views Breakpoint Types Evaluating and Displaying Expressions Testing with JUnit Refactoring Version Control with CVS In this module, you will learn about Eclipse’s debugging facility CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Debugging in Eclipse The Java Debugger Part of Eclipse Java Development Tools (JDT) More than System.out.printn(̎̎̎̎error̎̎̎̎) Detects errors as code executes Correct errors as code executes Actions you can perform debugging include: Control Execution Set simple breakpoints Set conditional breakpoints Review and change variable values Hot code replace (feature new to JRE 1.4) CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Debug Perspective Threads and Monitor View Variable View Editor View The debug perspective is a screen layout to help in debugging the code. It contains views that are specific for debugging. Perspective opens automatically when a breakpoint is hit during the execution of the Java application. However you need to run Java application in a debug mode, otherwise the execution will not stop at the breakpoint, and the breakpoint will be ignored. Console View Outline View Tasks View CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Simple Breakpoint Stops the execution of a program at the point Thread suspends at the location where the breakpoint is set Setting a breakpoint CTRL+Shift+B at current point in editor line Double click in editor’s marker bar at current line Breakpoints can be set by: Double-clicking on the left bar beside the line in the editor where you want to add the breakpoint Choosing Add Breakpoint from the context menu on the bar in the editor CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Starting a Debugging Session Select Java class containing the following: main() method Resulting execution will pass breakpoint Select Run » Debug As » Java Application Or Select Debug As » Java Application from the drop-down menu on the Debug tool bar. Debugging session usually starts on a Java application, i.e. class containing the main() method. The debugging session can also start if you execute Java code from the Scrapbook and a breakpoint is encountered during the execution. CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Debug Session Execution suspends prior to the line with a breakpoint You can set multiple breakpoints CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Deleting Breakpoints Double-click on the breakpoint in the editor Another way to remove the breakpoint is by choosing Remove Breakpoint from the context menu on the breakpoint. CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Control Execution From Breakpoint… Step Into or F5: For methods, execute method and suspend on first statement in the method For assignments, similar to Step Over For conditionals, similar to Step Over Step Over or F6 Execute next statement Step Return or F7 Resume execution to the end of the method on the next line after it was invoked Control Execution toolbar buttons are used for controlling the debugging session. CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Control Execution From Breakpoint Resume or F8 Continue execution until program ends or another breakpoint is reached Terminate Stops the current execution thread CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Variables and Fields To see the values bound to fields: Use Variables View Select variable in editor and select Inspect CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Code Debugging in this Module public class Debug { private int something = 0; private Vector list = new Vector(); public void firstMethod(){ thirdMethod(something); something = something + 1; } public void secondMethod(){ something = something + 2; public void thirdMethod(int value){ something = something + value; public static void main(String[] args) { Debug debug = new Debug(); debug.firstMethod(); debug.secondMethod();} CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Variables View Shows all fields of instance where breakpoint occurred Select this to see all fields Select any field to see value If field is bound to an object, you can select Inspect from the menu to view its fields and values CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Changing Field Values To change field value: Select field in Variables view Select Change Variable Value from the menu Enter new value into Set Variable Value window Click OK CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Expressions View Remembers all objects you have inspected Displays the fields of the object You can see the values of the fields You can Inspect the fields Opens when: You Inspect an object You click on the Expressions tab Expression view is used with the Inspector. You can also invoke the view from a Scrapbook by selecting the Java code and choosing Inspect from the context menu. CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Breakpoint View Lists all available breakpoints Can be used for manipulating breakpoints (through the views menu): Enabling Disabling Removing Also displays breakpoints properties Accessed like other debugging views Breakpoint View can be opened by clicking on the Breakpoints tab in the Debugging Perspective. Breakpoints can be manipulated in the Breakpoint View, meaning that you can remove, enable, or disable breakpoints. Double-clicking on the breakpoint in the view opens up an editor on the code where the breakpoint is set, and selects the line with the breakpoint. Breakpoints properties are viewed by choosing Breakpoint Properties from the context menu on a breakpoint. It is possible to set conditional breakpoints from the properties view. These breakpoints stop the execution only if the condition evaluates to true. To specify condition select the Enable Condition in the properties window and specify the condition. CSC/ECE 517 Fall 2009 Lec. 2

Method and variables are shown in the editor for the selected frame Debugging » Debug View Shows: Active threads Current stack frame when execution has stopped Previous stack frames Method and variables are shown in the editor for the selected frame Update in the editor updates the source When you debug, an editor on code that you debug is available in the perspective. When the execution stops at the break point editor shows (highlights) the line where the breakpoint is. Using debugging controls results in editor showing different methods, variables, etc. You can change the code in the editor directly, save the change, and continue with the debugging. CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Breakpoint Types Breakpoints can be set for the following Java entities: Line (simple breakpoint) Method Field (watchpoint) Java Exception Each breakpoint is set a different way and has different properties Watchpoint suspends execution when a particular field is about to be accessed. CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Method Breakpoints To set method breakpoint: Select method in the Outline View From context menu select Toggle Method Breakpoint To set breakpoint’s properties: Select breakpoint in editor. From the context menu, select Breakpoint Properties.. from the context menu In the Properties dialog, Check Enabled to enable the breakpoint Check Hit Count to enable hit count. Breakpoint suspends execution of a thread the nth time it is hit, but never again, until it is re-enabled or the hit count is changed or disabled. Choose Enable condition to have breakpoint enabled only if the specified condition occurs. condition is 'true' option: Breakpoint stops if the condition evaluates to true. The expres-sion provided must be a boolean expression. value of condition changes option: Breakpoint stops if result of the condition changes. You cannot specify a condition for method breakpoints, i.e. methods breakpoints cannot be conditional. CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Field Breakpoints Also known as watchpoint To set the watchpoint: Select field in the Outline View From context menu select Toggle Watchpoint To set watchpoint’s properties: Select breakpoint in editor Select Breakpoint Properties.. from context menu Set properties as desired Access/modification, enable Execution suspended on access/modification of field You cannot specify condition for field breakpoints, i.e. field breakpoints cannot be conditional. CSC/ECE 517 Fall 2009 Lec. 2

Debugging » Java Exception Breakpoint To Add Java Exception Point: Select Run » Add Java Exception Breakpoint from main menu Enter exception type Specify what triggers a breakpoint: Caught exception Uncaught exception Both CSC/ECE 517 Fall 2009 Lec. 2

Debugging » How To Debug Here are simple steps for debugging in Eclipse: Set your breakpoints Hit a breakpoint during execution Walk/step through code to other breakpoints Follow along in editor Inspect/Display interesting fields Watch the Console for things to happen Debugging is an important facility of any development environment. Eclipse debugger contains facilities that help you in debugging the code. You will find that inspecting objects is probably most commonly used activity during the debugging. Watch what happens during the debugging, i.e. watch for field, variables values. CSC/ECE 517 Fall 2009 Lec. 2

You have learned: The views in the Debug Perspective Debugging » Summary You have learned: The views in the Debug Perspective Typical debug session How to use the Inspector About the different types of breakpoints How to set breakpoints How step around your code doing debugging CSC/ECE 517 Fall 2009 Lec. 2

What happens to the program execution? Debugging » Exercise 2 Set a breakpoint in the printField method of the class NewClass that was created in Exercise 1. Start a debug session. What happens to the program execution? What do you see in the debug windows? CSC/ECE 517 Fall 2009 Lec. 2

Module Road Map Overview Installing and Running Building and Running Java Classes Debugging Testing with JUnit What is JUnit? Where Does it Come From? Working with Test Cases Working with Test Suites JUnit Window Refactoring Version Control with CVS In this module, you will learn about Eclipse’s built-in JUnit facility. CSC/ECE 517 Fall 2009 Lec. 2

What is JUnit? Regression testing framework Written by Erich Gamma and Kent Beck Used for unit testing in Java Open Source Released under IBM's CPL Deugo’s presentation on JUnit: http://www.cs.umd.edu/class/spring2006/cmsc132/EclipseTutorial/Dwight-Deugo-Presentation-JUnit.pdf CSC/ECE 517 Fall 2009 Lec. 2

Testing » Where Does JUnit Come From? JUnit’s web site: http://junit.org/index.htm Eclipse includes JUnit Eclipse provides new GUI to run JUnit test cases and suites JDT tools include a plug-in that integrates JUnit into the Java IDE Allows you to define regression tests for your code and run them from the Java IDE. You can run your unit tests outside of Eclipse If you wish using TestRunner Using JUnit’s Window TestRunner is explained at http://junit.sourceforge.net/doc/cookbook/cookbook.htm. This sites introduces JUnit testing outside of Eclipse. CSC/ECE 517 Fall 2009 Lec. 2

Testing » Including JUnit in a Project In the Package window, right-click on the name of the project Choose “Properties”; then select “Java Build Path” Click on the “Libraries” tab, and then choose the “Add Library” button on the right. Select “Junit” and click “Finish”. CSC/ECE 517 Fall 2009 Lec. 2

Testing » Eclipse JUnit Setup Eclipse preferences can be set in the JUnit Preferences window (Window » Preferences from the main menu. Expand Java in the Preferences window) For the most part you can leave the preferences alone Filters needed to identify packages, classes, or patterns that should not be shown in the stack trace of a test failure CSC/ECE 517 Fall 2009 Lec. 2

Testing » JUnit Test Cases Runs multiple tests Implemented as subclass of TestCase Define instance variables that store the state of the tests in the class Initialize TestCase by overriding setUp method Clean-up after test case is done by overriding tearDown method The Test framework will invoke the setUp and tearDown methods. CSC/ECE 517 Fall 2009 Lec. 2

Testing » Creating JUnit Test Cases in Eclipse Create a new package to contain your test case classes Add the JUnit JAR file to the project’s buildpath CSC/ECE 517 Fall 2009 Lec. 2

Testing » Creating JUnit Test Cases in Eclipse Select your testing package From the context menu select New » JUnit Test Case. This opens the New JUnit Test Case Wizard. Fill in the name of your test case in the Name field. Select the method stubs that you want Eclipse to generate This will create the corresponding class in your testing package CSC/ECE 517 Fall 2009 Lec. 2

Testing » JUnit TestCase Template public class NewTestCase extends TestCase { public static void main(String[] args) { } public NewTestCase(String arg0) { super(arg0); protected void setUp() throws Exception { super.setUp(); protected void tearDown() throws Exception { super.tearDown(); CSC/ECE 517 Fall 2009 Lec. 2

Testing » Adding Tests to Test Cases Any method in a TestCase class is considered a test if it begins with the word “test”. You can write many tests (have many test methods) Each test method should use a variety of assert… methods to perform tests on the state of its class. Assert methods are inherited CSC/ECE 517 Fall 2009 Lec. 2

Testing » JUnit Assert Methods Assert methods include: assertEqual(x,y) assertFalse(boolean) assertTrue(boolean) assertNull(object) assertNotNull(object) assetSame(firstObject, secondObject) assertNotSame(firstObject, secondObject) CSC/ECE 517 Fall 2009 Lec. 2

Testing » Adding Two Tests to JUnit Test Case public class NewTestCase extends TestCase { public static void main(String[] args) { } public NewTestCase(String arg0) { super(arg0); protected void setUp() throws Exception { super.setUp(); protected void tearDown() throws Exception { super.tearDown(); public void testCompareSucceed() { assertEquals(0, 0); //this assertion will succeed public void testCompareFail() { assertEquals(0, 1); //this assertion will fail CSC/ECE 517 Fall 2009 Lec. 2

Testing » Running JUnit Test Case Select TestCase class From the Run menu select Run » Run As » JUnit Test This will run the tests in your TestCase class along with the setUp and tearDown methods You will then get a report in the JUnit window CSC/ECE 517 Fall 2009 Lec. 2

Red indicates a test has failed You can see which test failed Testing » JUnit Window Red indicates a test has failed You can see which test failed You can see the call trace leading to the failure If you wish to see the tests in TestCase click on the Hierarchy tab CSC/ECE 517 Fall 2009 Lec. 2

You can see how many tests ran How many failures occurred Testing » JUnit Window You can see how many tests ran How many failures occurred You can see the details of the failure Errors occur when exceptions are thrown CSC/ECE 517 Fall 2009 Lec. 2

Testing » Creating JUnit Test Suite Runs multiple test cases or suites To create a TestSuite Select your testing package From the context menu select New » Other… Then from the Wizard select Java » JUnit » JUnit Test Suite Motivation for creating a JUnit Test Suite: Multiple classes can be tested at once. CSC/ECE 517 Fall 2009 Lec. 2

Testing » Creating JUnit Test Suite Fill in the name of your TestSuite class Select the TestCases to include in your TestSuite CSC/ECE 517 Fall 2009 Lec. 2

Testing » Unit Test Suite Template import com.test; import junit.framework.Test; public class AllInclusiveTestSuite { public static Test suite() { TestSuite suite = new TestSuite("Test for com.test"); //$JUnit-BEGIN$ suite.addTestSuite(NewTestCase.class)); suite.addTestSuite(SecondTestCase.class)); //$JUnit-END$ return suite; } CSC/ECE 517 Fall 2009 Lec. 2

Testing » Running JUnit Test Suite Select TestSuite class From the Run menu select Run » Run As » JUnit Test This will run the test cases in your TestSuite class You will then get a report in the JUnit Window CSC/ECE 517 Fall 2009 Lec. 2

Testing » JUnit Test Interface The JUnit classes TestCase and TestSuite both implement the JUnit Test interface Therefore, you can add JUnit TestSuites to other TestSuites public static Test suite() { TestSuite suite = new TestSuite("Test for testing"); //$JUnit-BEGIN$ suite.addTestSuite(FirstTestCase.class); suite.addTestSuite(SecondTestCase.class); suite.addTest(AllTests.suite()); //$JUnit-END$ return suite; } Motivation for adding TestSuite to another TestSuite: Test suites written in another package (written by others) can be tested within a test suite in one shot. CSC/ECE 517 Fall 2009 Lec. 2

Exercise 3 Create a JUnit test case class TestClass for the package csc517 of the project EgApp. Add a test method testBoolean to the class TestClass. In the method testBoolean, invoke the assert routine assertTrue with the argument “0” (FALSE). Run the test case. What do you see in the JUnit window? Now invoke the assertTrue routine with the argument “1” (TRUE). Run the test case. What is the output in the JUnit window? assertTrue is inherited CSC/ECE 517 Fall 2009 Lec. 2