Performance and Test

Setup for Lab exercises

This guide will explain how to use the pre-installed software on the machines in the lab as well as describe how to install on your own computer.

Usage

Working with Eclipse

Setting up a Java project in Eclipse

First specify Java 1.5 as default, do this by choosing

Window->Preferences->Java->Compiler->Compiler Compliance Level: 5.0.

This setting is global for all Java projects.

Choose File->New->Project. Highlight Java Project and click next.

On the next screen name your project and check that it’s using Java 1.5. Click next and finish.

To create a new class, right click the project in the package explorer and choose New->Class.

Indicate the class name and package and click Finish.

Compiling and launching programs in Eclipse

Unless told to do otherwise Eclipse automatically compiles the project when changes are saved to files. It will also dynamically indicate problems with the code.

To set up a launch profile for the project, click the downward arrow next to the green ‘play’ icon and choose ‘Run…’. Double-click ‘Java Application’ to create a new launch profile. Eclipse should automatically have added your class if it has a main method. The Main Class option specifies which class’ Main method to launch. The Arguments tab allows you to provide command line arguments for your own program as well as the Java Virtual Machine.

Click run to test the launch profile. When you need to run again, you can click the ‘play’ icon to launch the last used profile, or click the downwards arrow to choose among profiles.

Adding JUnit to the buildpath

Right click your project in the package explorer and choose Properties->Java Build Path->Add Library, click JUnit and choose next. In the next screen you can choose the JUnit version. JUnit 4.x is backwards compatible so you might as well choose 4.x.

Working with JUnit 3.8 in Eclipse

To create a TestCase class, right click the project and choose New->New JUnit Test Case. In the form presented choose to create a 3.8 JUnit test case. Fill out the rest of the form and click next to choose the methods to test or click finish if you want to do it manually. 3.8 JUnit test methods need to have a name that starts with ‘test’.

To run the unit test, proceed as to make a new launch profile, but this time choose JUnit instead of Java Application.

Working with JUnit 4.x in Eclipse

To create a test method without creating a new TestCase class, open the Java file for the class that implements the test(the class to be tested or a dedicated test class) and add an import for org.junit.* in addition to import static org.junit.Assert.*; The procedure must be marked with the annotation @Test to indicate it’s a Junit test method.

You can also use New->New JUnit Test Case as described above, the only difference being that you choose to make it a JUnit 4 testcase.

To run the unit test, proceed as to make a new launch profile, but this time choose JUnit instead of Java Application. Make sure JUnit 4 is selected and click run.

Using Jmock

To use jMock in a project you must as minimum add jmock-1.1.0.jar to the build path. To do this right click your project and choose Properties->Java Build Path. Click add external Jar and locate jmock-1.1.0.jar.

You can read here how to use jMock to create mock objects corresponding to an interface:

http://www.jmock.org/getting-started.html

If you need to mock a concrete class you need to add the two other Jar files downloaded to the build path as well.

Further instructions can be found here:

http://www.jmock.org/cglib.html

Using the eclemma Junit Line Coverage plug-in

When performing unit tests it is essential to know how much of the code base is covered in the tests. We suggest using the eclemma plugin which has been pre-installed. Instructions can be found at:
http://www.eclemma.org/userdoc/index.html

Creating a CVS repository

Log into a Unix command line at ITU (either directly from a Linux machine or by connecting to ssh.itu.dk using an SSH client and your Unix username and password).

Let <path> be the FULL path of your desired CVS repository (for example /import/home/username/cvs).

Execute the following from the command line:

cvs –d <path> init

Working with CVS in Eclipse

For this guide we will assume a CVS repository located at ITU in the directory /import/home/username/cvs

Click Window->Show Perspective->Other..

Choose CVS Repository exploring.

Right click in the CVS repositories view and choose ‘New’. Enter the following:

Hostname: ssh.itu.dk

Repository path: /import/home/username/cvs

User: your linux username

Password: Your linux password

Connection: extssh

Note that these setting will also allow you to access the CVS repository from home.

If you wish to checkout a project from CVS, you can expand the repository you created, find the version you want, and right click it. If you just want the files directly, click checkout. If you want to create a project based on the content click ‘Check out as’.

To import a project into CVS, right click the project and choose Team->Share Project, you can then use an existing repository location or create a new one.

In general for performing CVS operations, right click the shared project and choose for example Commit or Update.

What about Subversion (SVN) ?

Feel free to use SVN in place of CVS. In order to use SVN from Eclipse you will need the Subclipse plugin. Follow this guide to install the plugin: http://subclipse.tigris.org/install.html.

You will also need to create a SVN repository. In order to do this, proceed according to 'Creating a CVS repository', and simply invoke the command 'svnadmin create <PATH>'. The setup in Eclipse for the repository is very similar to CVS, but in this case the URL for repository is 'svn+ssh://<username>@ssh.itu.dk/<PATH>'. If you created your repository in your home directory in a folder called svn, this translates into : 'svn+ssh://<username>@ssh.itu.dk/import/home/<username>/svn/' .

Finally, go to Window -> Preferences -> Team -> SVN, and make sure that 'SVN Interface' is set to 'SVNKit (Pure Java)'.

Working with Ant in Eclipse

In your Java project, create a new text file and save it as build.xml. This will be your build file. Now click the down arrow next to the play icon with the red suitcase(henceforth Run External button) and click External Tools. Double-click Ant-Build to create new build launcher. Note the different available settings in the tabs, and then choose build.xml as your buildfile and choose an appropriate base directory (your project directory for example). When your buildfile has some targets defined, you can indicate which ones to run here. Now click close. You can setup multiple build launchers for different targets, just as you can create multiple launch profiles for a project.

Installation

Windows

Installing Eclipse

Download the following file to your home directory:

http://www.itu.dk/people/petert/files/eclipse-SDK-3.2-win32.zip

Unzip it to a location of your choice.

Launch eclipse.exe. When prompted give a workspace location in your home directory.

Linux

Go to

http://download.eclipse.org/eclipse/downloads/drops/R-3.2-200606291905/index.php

and choose the version depending on your setup. Unpack to your home directory.

Launch eclipse and provide a workspace location in your home directory.

Installing jMock

Go to:

http://www.jmock.org/download.html

Download the first two Jar files mentioned. Then go here:

http://prdownloads.sourceforge.net/cglib/cglib-nodep-2.2_beta1.jar?use_mirror=heanet

and download that Jar file as well.

Place them in a directory called javalibs(or something to that effect) in your home directory.

Installing eclemma

Please follow the guide at : http://www.eclemma.org/installation.html

A few nice tips and tricks for Eclipse

Auto-Import

If you use a class which you haven’t imported you can mark its name in the editor and hit Ctrl-Shift-M to let Eclipse perform the import automatically.

Line numbers

The default editor doesn’t show line numbers, you can change this in Window->Preferences->General->Appearance->Editors->Text Editors: Show Line numbers.

Re-factoring

Eclipse supports re-factoring of Java code. If you have a class, method, field or similar which you need to rename you simply highlight its definition/name, right-click and choose Refactor. This brings up for example rename. You can use this to rename the selected item, and all references to it in the code will be updated as well. If you forget to add getters and setters for a field, and later find that this was a bad idea, you can use the Encapsulate field to automatically generate getters and setters and redirect all use of the field to these.

Eclipse as CVS client

Eclipse can be used as CVS client for any kind of project, not only Java stuff. By using the 'Simple' project type you can easily use Eclipse for CVS and take advantage of its nice conflict resolution editor.

Links to guides etc

http://help.eclipse.org/help32/index.jsp

http://open.ncsu.edu/se/tutorials/

http://www.cs.umd.edu/class/fall2004/cmsc131/EclipseTutorial/