Programming Tools Eclipse JUnit Testing make and ant.

43
Programming Tools Eclipse JUnit Testing make and ant
  • date post

    22-Dec-2015
  • Category

    Documents

  • view

    223
  • download

    2

Transcript of Programming Tools Eclipse JUnit Testing make and ant.

Page 1: Programming Tools Eclipse JUnit Testing make and ant.

Programming Tools

Eclipse

JUnit Testing

make and ant

Page 2: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 2

Development Environments• Command line

– gvim/emacs– javac– java

• Integrated Development Environment– provides access to all the tools from a

single interface– Eclipse (3.3.2)

Page 3: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 3

Eclipse• "universal tool platform"• Developed by IBM

– Now an open source project• http://www.eclipse.org/downloads

• Primarily a development environment for Java– written in Java– Extendible

• Plug-ins can be added to support new functionality and other languages

Page 4: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 4

Eclipse Workbench• Provides the basic graphical interface• Divided up into views

– Navigator shows all projects– Editor has panes for all open files

• Views are organized into perspectives– a perspective contains a set of views that

are needed for a particular task• Java perspective• debug perspective

Page 5: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 5

Command Line Arguments in Eclipse

• To use command-line arguments, you need to create a Run Configuration for the project.

• From the Run menu (or the Run drop-down), select Open Run Dialog

• Create a new Run Configuration (or modify an existing on for the project)– Click the Arguments tab– Type the desired command-line arguments into

the Program Arguments text box– Click Apply and then Run

Page 6: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 6

IO Redirection in Eclipse

• Append the redirection operators to the command-line arguments

• Create a script to use as an external tool

Page 7: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 7

JUnit Testing

• JUnit is an open-source testing framework for Java– facilitates the writing of test cases

• You can create test cases and test suites by extending the appropriate class from the JUnit package

Page 8: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 8

JUnit Testing

• JUnit has been integrated into Eclipse

• Make sure junit.jar is on the build path– use the Properties menu– or let Eclipse find it when you create the

test case

• Create a test case– File -> New -> JUnit Test Case

• Run your application as a JUnit Test

Page 9: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 9

In the TestCase class

• Write methods that test each of the methods of your class– use the assertion methods on next slide for

testing results of methods

• You can override setup() and teardown() to create a set of objects to be shared by several tests

Page 10: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 10

Assertion methods

• assertEquals( expected, actual) for primitives

• assertFalse( condition), assertTrue(condition)

• assertNull( object), assertNotNull( object)

• assertSame( ecpected, actual), assertNotSame(expected, actual)

Page 11: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 11

Sources of Information

• The home page for JUnit is at http://www.junit.org/

• The documentation is at http://junit.sourceforge.net/javadoc/

Page 12: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 12

Debugging

• Compile time– Compiler forces your code to have correct

syntax

• Run time– How do you figure out what is wrong with a

program that isn't running correctly?– What information do you need?

Page 13: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 13

Debuggers• A debugger is a tool that is designed to help

you figure out what is going wrong in a program.

• Useful functionality– Start the program and have it stop just before

where you think the error occurs– Look at (and modify) variable values– Look at the call stack– Step through parts of the program one line at a

time

Page 14: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 14

Debugging in Eclipse• The debug perspective provides the

views needed for debugging.– Debug view – Variable View– Breakpoints view– Expressions view– Editor view– Outline and Console views are the same

as in the java perspective

Page 15: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 15

Debug View• Shows stack frames for any programs

currently being debugged• Buttons allow you to

– Resume - start from current instruction and continue to next breakpoint or end of program

– Suspend (e.g. for infinite loop) – Terminate stops the program– Remove all terminated launches

Page 16: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 16

Editor View• Essentially the same as in the Java

perspective• Breakpoints are marked at the edge of

the frame– Left click and select toggle breakpoint

• An arrow marks the next statement to execute

• Hovering mouse over a variable name will show its value

Page 17: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 17

Breakpoints

• A breakpoint is used to mark lines of code where you want the program to stop.– Once the program stops, you can examine

all the variables

• Breakpoint view shows all breakpoints and allows you to manage them– Disable, enable, remove, remove all

Page 18: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 18

Other kinds of Breakpoints• Watchpoints - suspend when the program is

going to change an instance variable– Run-> Add/Remove Watchpoint

• Method breakpoints - suspend on entry to or exit from a method– Run-> Add/Remove Method Breakpoint

• Exception breakpoints - suspend on a particular Exception– Run-> Add/Remove Exception Breakpoint

Page 19: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 19

More on Breakpoints• You can set breakpoints with hit counts

– program stops when the breakpoint has been reached the specified number of times

– Right-click on the breakpoint in the breakpoint view

• You can also set a breakpoint to trigger– when a variable changes– when a Boolean expression is true

Page 20: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 20

Stepping through code

• Step into goes into the code of a method that is being called

• Step over executes the entire method call

• Step return completes the current method call – Stops at breakpoints or at the point from

which the method was called

Page 21: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 21

Values and Expressions

• Double clicking on a variable in the Variable view allows you to change its value– new value is used when the program

resumes

• Type an expression into the Expression view to find out what its value is

Page 22: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 22

UML Diagrams

• Class diagrams

• Object diagrams

• Tools– dia– umbrello– violet

Page 23: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 23

UML Class Diagrams

• Used to illustrate relationships between classes

• Used to show the details of a particular class

Page 24: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 24

UML Symbols

Symbol Visibility

+ public

- private

# protected

~ package

Relationship Connector

inheritance (is-a)

open arrow

association (uses)

solid line

aggregation/

composition

(has-a)

open/

solid

diamond

inner class circle with cross

Page 25: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 25

Inheritance

Page 26: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 26

Class Hierarchy

Page 27: Programming Tools Eclipse JUnit Testing make and ant.

Fall 2007 CS 225 27

UML Class Diagram

Page 28: Programming Tools Eclipse JUnit Testing make and ant.

Fall 2007 CS 225 28

UML Object Diagram• Used to represent the state of the program at

some particular time

Page 29: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 29

Tools for UML Diagrams

• dia

• umbrello

• violet

• Eclipse plug-in

Page 30: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 30

Building Big Projects• For very large projects, the process of recompiling all

the modules that make up the project can take a long time.

• One way to reduce the amount of time needed to build a project is to only recompile the modules that have not changed and don't use modules that have changed.

• Two tools that determine what needs to be recompiled.– make– ant (for Java)

Page 31: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 31

The make Utility• make is a command generator designed to

help you manage large projects– make allows you to specify dependencies between

modules• if a class depends on another class, it should be

recompiled when that class changes

– make allows you to specify how to compile a particular class

– make uses these specifications to determine the minimum amount of work needed to recompile a program

Page 32: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 32

How does make Work?• make uses a file called Makefile (or makefile

or GNUMakefile) to determine what needs to be recompiled.

• The makefile contains a set of rules for executing the jobs it can be asked to do.

• When you run make, it uses the rules in the makefile to determine what needs to be done.

• make does the minimum amount of work needed to get the job done.

Page 33: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 33

The Makefile• A make file consists of a set of rules• Each rule has the form

target: dependencies commands

• target is (usually) the name of a file to be created• dependencies are the names of files that are needed

to create the target• commands is one or more commands that need to be

executed to create the target. • Each command is indented with a tab

Page 34: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 34

Example

• TestPriorityQueue uses KWPriorityQueue. PrintDocument and ComparePrintDocuments objects

• ComparePrintDocuments uses PrintDocument objects

• KWPriorityQueue implements Queue

Page 35: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 35

makefileTestPriorityQueue.class: TestPriorityQueue.java \

KWPriorityQueue.class PrintDocument.class \

ComparePrintDocuments.class

javac TestPriorityQueue.java

KWPriorityQueue.class: KWPriorityQueue.java Queue.class

javac KWPriorityQueue.java

Queue.class: Queue.java

javac Queue.java

Page 36: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 36

makefile (cont.)ComparePrintDocuments.class: \ ComparePrintDocuments.java PrintDocument.class javac ComparePrintDocuments.java

PrintDocument.class: PrintDocument.java javac PrintDocument.java

Page 37: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 37

Dummy targets

• The makefile can also have targets that don’t create files

• A target to run a java programTestPriorityQueue: TestPriorityQueue.class

java TestPriorityQueue

• A target to remove class filesclean:

rm -f *.class

Page 38: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 38

Sources of Information

• Managing Projects with make by Andrew Oram and Steve Talbot

• http://www.delorie.com/gnu/docs/make/make_toc.html

• Look at the man pageman make

Page 39: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 39

Ant

• make can be used with Java files

• ant was designed for building large Java projects– acronym for "Another Neat Tool"

• Ant uses XML format for build files

Page 40: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 40

build files• A build file is an xml file that contains

exactly one project element<?xml version="1.0" ?><project default="main">

</project>• main is target to build if none is given• name and basedir are optional

attributes for project

Page 41: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 41

Targets• A project element contains one or more

targets• Each target corresponds to a task

– the main target is required<target name="main>

</target>

• depends attribute contains list of targets that this target needs

Page 42: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 42

Tasks• Each target contains one or more tasks• There are a number of built-in tasks

– java • needs the classname attribute to be set to the main class

– javac

– jar - to create a java archive– javadoc - to create the documentation

Page 43: Programming Tools Eclipse JUnit Testing make and ant.

Spring 2010 CS 225 43

Sources of Information

• Ant The Definitive Guide by Steve Holzner

• Ant is an open source Apache project– http://ant.apache.org/