View
225
Download
0
Embed Size (px)
Citation preview
Fall 2007 CS 225 1
Programming Tools
EclipseJUnit Testingmake and ant
Fall 2007 CS 225 2
Eclipse
• command line arguments
Fall 2007 CS 225 3
Debugging in Eclipse
Fall 2007 CS 225 4
JUnit Testing
• JUnit is an open-source testing framework for Java
• You can create test cases and test suites by extending the appropriate class from the JUnit package
Fall 2007 CS 225 5
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
Fall 2007 CS 225 6
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
Fall 2007 CS 225 7
Assertion methods
• assertEquals( expected, actual) • assertFalse( condition),
assertTrue(condition)• assertNull( object),
assertNotNull( object)• assertSame( ecpected, actual),
assertNotSame(expected, actual)• And many more
Fall 2007 CS 225 8
Sources of Information
• The home page for JUnit is at
http://www.junit.org/
• The documentation is at http://junit.sourceforge.net/javadoc/
Fall 2007 CS 225 9
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)
Fall 2007 CS 225 10
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
Fall 2007 CS 225 11
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.
Fall 2007 CS 225 12
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
Fall 2007 CS 225 13
Example
• TestPriorityQueue uses KWPriorityQueue. PrintDocument and ComparePrintDocuments objects
• ComparePrintDocuments uses PrintDocument objects
• KWPriorityQueue implements Queue
Fall 2007 CS 225 14
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
Fall 2007 CS 225 15
makefile (cont.)ComparePrintDocuments.class: \ ComparePrintDocuments.java PrintDocument.class javac ComparePrintDocuments.java
PrintDocument.class: PrintDocument.java javac PrintDocument.java
Fall 2007 CS 225 16
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
Fall 2007 CS 225 17
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
Fall 2007 CS 225 18
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
Fall 2007 CS 225 19
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
Fall 2007 CS 225 20
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
Fall 2007 CS 225 21
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
Fall 2007 CS 225 22
Sources of Information
• Ant The Definitive Guide by Steve Holzner
• Ant is an open source Apache project– http://ant.apache.org/