How To

A place where you can discover lots of interesting things - along with the hair pulled out to obtain these gems. Be sure to also check out the GettingStarted? page.


.

Using the Informational Tools

There are three major tools used for communication within the project. This section describes how to register and use these tools.

Status Reporting (blog)

For status report, please visit http://clforjava.cs.cofc.edu/MoveableType/mt.cgi.

Documentation Repository (TWiki - this tool)

TWiki is our primary document repository. It is used to hold non-temporal information such as this HowTo page, specifications, build information, explanatory information, and any other data that isn't temporal (status reports, discussions).

This is a Wiki system which lets anyone edit any page. You are encouraged to add new information or correct or expand on existing topics. The Wiki can be a bit confusing at first, so find someone who's done it before. But don't worry if you mess up - there's a revision system underneath, so any problems can be undone.

You register yourself in TWiki. Go to http://clforjava.cs.cofc.edu/twiki/bin/view/Main/WebHome to enter the main TWiki web. Look in the box labeled "TWiki Site Map". In the second row, you will see an underlined Registration link. Click that, fill in the form, and say ok. TWiki will register you with the password you choose. Please use your real first and last names in the registration and accept the Wiki name it creates (just your names concatenated). You log into TWiki using your Wiki name and password.

To quickly learn how to format text in TWiki, see http://clforjava.cs.cofc.edu/twiki/bin/view/TWiki/TextFormattingRules.

Discussion Forum (Simple Machines Forum)

The forum is just what it says. This is a new (FallSemester2005? ) tool suite and has been a great addition to the project. There are a number of boards for the various components of the product. Please use this for discussions, questions, insights, grumbles, pleas for help, - anything that's temporal. Contribute what you know; ask about what you don't.

The forum is at http://clforjava.cs.cofc.edu/forum/. You can register yourself. Be aware that this forum is open to the public (there are a few lurkers - the good kind). Please choose the display name that corresponds to your TWiki username (usually FirstLast? ).

Configuring Perforce for CLforJava?

Downloading the Perforce Software Configuration Management (SCM) System

  1. If you are using the Windows operating system, quickly download the installer (Ver. 2007.2) <a href="http://www.perforce.com/downloads/perforce/r07.2/bin.ntx86/p4vinst.exe"> here</a>, or
  2. Download the Perforce SCM System <a href="http://www.perforce.com/perforce/loadprog.html">here</a>
  3. Choose the link corresponding to your operating system (e.g., Windows, Linux)
  4. Then choose one of the three P4 Clients (e.g., P4V? -Perforce Visual Client) read the Release Notes and download/install the software.

Setting Up A <nop>ClientSpec using P4Win? (P4V? , Rev. Perforce Visual Client/NTX86/2005.1/85663)

You need to set up a <nop>ClientSpec to log into Perforce. Your <nop>ClientSpec contains the root directory where to put files on your machine. If you have different directories on different machines you need to create a different <nop>ClientSpec for each.
  1. Create a directory on your machine to store the project files (e.g., C:\CLforJava).
  2. Open up P4V? on your machine.
  3. You will see an "Open Connection" Dialog Box.
  4. Enter your server as: clforjava.cs.cofc.edu and port as: 1666.
  5. Under the "Connect as" fields, enter your Username and Password (defaults are username being your edisto login, sans @edistocofc.edu; your password is your first name, capitalized.)
  6. Click "New" next to the "Workspace" field. Enter a name for your Workspace, such as "CLforJava".
  7. Click OK, and your connection should be set up.

Setting Up A Connection Using Perforce Visual Client - P4V? _24X86 (Linux/Unix)

Once you have installed the Perforce Visual Client, follow these simple steps:
  1. Create a directory on your machine to store the project files (e.g., ~/CLforJava).
  2. Run the P4V? Client. You should see an Open Connection window.
  3. Change server field to "clforjava.cs.cofc.edu" and Port field to "1666".
  4. On the Connect as section, use your user name and password (defaults are username being your edisto login, sans @edistocofc.edu; your password is your first name, capitalized.)
  5. Create a new workspace under section three by clicking "New..."
  6. Enter a name for your new workspace (e.g. <nop>CLforJava).
  7. Set the root field to the root directory (Step 1) on your machine to store the project files.
  8. Click Save to create the workspace, then OK to open the connection.

Syncing to Perforce

P4Win:
- After creating a client spec, right click on the //depot -> Sync to Head. This may take a few minutes if it is your first time. You now have all the project file in your root directory on that machine.

P4V (Rev. Perforce Visual Client/NTX86/2005.1/85663):
- After opening a connection, right-click on the "//" node of the Depot Tree (left side) and select "Get Latest Revision". All the project files will be syncronized to your current workspace. (If an error arises you may have the same workspace name as someone else trying to access the project. Try using something unique to you, one suggestion would be CLforJava? for a workspace name.) Remember, you may only need to sync the "CLforJava" branch of the depot.

Handling <nop>ChangeLists

After logging on to Perforce and openning the file you wish to edit by going to the file through the depot root directory structure and selecting it "Open for edit" and clicking the Command button titled: "Open for edit" you must submit it back to Perforce.

Submit the file by selecting "Submit default changelist..." from the drop down menu and clicking the "Run" button. This will bring you to a window that let you select what file to submit. Make sure that you choose the second option. For example, Files in//depot/CLforJava/src/java/lisp/common/and subdirectories. This should be your default but if not select it. Before clicking the "Continue" button make sure your using files "checked" is selected. This will bring your to another window where you want to give a very descriptive explantion what you did with the file for example if you changed the constructor method from public to private, write so then click "Submit" button. This should bring you to a window that that has similar writing: Command:
submit
Result:
Change 339 created with 1 open file(s).
Submitting change 339.
Locking 1 files ...
edit //depot/CLforJava/src/java/lisp/common/Package.java#32
Change 339 submitted.

This should indicate successfully submission, but make sure by going to the file and making sure that it is not "Open for edit".

Branching in P4Web?

From the P4Web? main page:
  1. Select Run => Create Branch Spec
  2. Name the branch in the Branch field and fill out a description in the Description field
  3. Leave the check boxes unchecked
  4. In the View field, you're input should look something like this: //depot/(branch that you wish to branch from -- generally <nop>CLforJava)/...//depot/(your branch name)/...
  5. Click Save
  6. Select Go To => Branches
  7. Select your branch from the list
  8. Select Run => Integrate using branch spec...
  9. On the next screen, leave all the selections on their default values and select Preview Integration to see the files that will be included in the branch or Integrate to begin the integration process
  10. When the integration is complete, select Go To => Depot Root -- you should see all the files to be included in the branch listed on the depot
  11. Select Run or Integrate
  12. Make the follow selections => Current Path: //depot/(branch you are branching from), Direction to Integrate Changes: From files in current path, Use corresponding path: //depot/(your branch name), Use Branch Spec: (your spec name from Step 5), and Integrate all files in Branch Spec => Forward
  13. Click Integrate
  14. Go To => Depot Root
  15. To submit changes and create the branch select Run => Submit Default Changelist or Run => Revert to ignore changes

Configuring <nop>Netbeans for CLforJava?

Note theses instructions are the same as found on Netbeans.org, however they have been slightly modified for this project.

Downloading <nop>NetBeans Integrated Development Environment (IDE)

The version of <nop>NetBeans and Java JDK that are currently being used by CLforJava? are <nop>NetBeans IDE Release 6.8 and JDK 1.6. A bundled version of both can be downloaded <a href="http://java.sun.com/javase/downloads/widget/jdk_netbeans.jsp">here</a>. Install these software packages, then follow the steps in the next section.

How To Configure CLforJava? in <nop>NetBeans

For a visual depiction of the following steps, see http://clforjava.cs.cofc.edu/TWiki/pub/DevEnvironment/HowTo/CLforJavaNetbeansTutorial.pdf
  1. Before you start, make sure you have downloaded Perforce and been able to successfully sync the project to your computer (See PerforceVersionControl).
  2. Open Netbeans. On the Welcome tab, choose New Project, or File -> New Project...
  3. Choose Java under Project Catagories: select Java Free-Form Project, then click Next. (If you have a problem in Netbeans with a warning like 'Invalid ant file,' Try deleting the files that you got with Perforce and re-synching.)
  4. Name and Location Step: browse to the folder you created called <nop>CLforJava and click Open. <nop>NetBeans will fill in the remaining fields with the appropriate information needed. If it does not you will have to browse to the "build.xml" and click open for the Build Script selection. Check and verify your fields match page 4 of the Installing-NetBeans pdf file. Click Next.
  5. Build and Run Actions Step:
    • Build Project: choose <nop>CLforJava
    • Clean Project: choose Clean
    • Generate Javadoc: choose <nop>GenerateJavaDoc
    • Run Project: choose <nop>CLforJava
    • Test Project: choose <nop>RunSmokeTestSuite
Click Next.
  1. Source Package/Test Package Folders Step: Click on the <nop>AddFolder button next to the Source Package Folders field, navigate to the C:\%YOUR_PATH%\CLforJava\src\java (be careful to only highlight the java folder) and click Open. Repeat this step for the Test Package Folders field located below, add the folder ...\test\src\java, then click Open. Make sure you have JDK 1.5 selected as your Source Level. Click Next.
  2. Classpath Step:Add these paths to both the src\java and test\src\java Source Package Folders.
    • Click Add JAR/Folder... -> browse to C:\%YOUR_PATH%\CLforJava\extensions\junit4.5\junit-4.5.jar and click Open.
    • Click Add JAR/Folder... -> browse to C:\%YOUR_PATH%\CLforJava\lib\Apache\commons-io-1.3.2.jar and click Open.
    • Click Add JAR/Folder... -> browse to C:\%YOUR_PATH%\CLforJava\lib\asm-all-3.2.jar and click Open.
    • Click Add JAR/Folder... -> browse to C:\%YOUR_PATH%\CLforJava\build\classes and click Open.<---The build\classes directory is only available after the project has been built. It is only needed if you plan to use JUnit to perform testing. If needed,you can build the project then add this directory by editing the project properties.
Note: Make sure you have JDK 1.6 selected as your Java Platforms.
  1. Choose Finish to complete the <nop>NetBeans 6.8 Project setup.

Configuring the Debugger

The debugger is a powerful tool in <nop>NetBeans that allows you to track bugs and find values of variables during runtime.

<nop>NetBeans 4.1+ Debugging

  • Set your breakpoints in Netbeans.
  • Start your CLforJava? system with:
    • java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=11555 -jar C:\CLforJava\CLforJava\build\dist\lib\CLforJava.jar
  • In Netbeans go to Run->Attach Debugger
  • Set port as 11555 and click Ok

<nop>NetBeans <4.0 Debugging

You are now debugging "remotely" and have the ability to use the system with full input capabilities as well as full debugging capabilities.

  1. Go to Tools -> Options
  2. Go down to Debugger Settings and press the plus sign
  3. Click on java
  4. On the right, uncheck the box that says "Run Compilation"
Remember that when you run CLforJava? , you must right click and press execute on the CLASS file, not the java source file for this to work.

Setting <nop>NetBeans compiler to target your files

Since this will help your tests run a little smoother, it is recommended that you follow these instructions. This will set up the compiler that will place the compiled classes for src and test in the correct build directories.

Note
No equivalence found for <nop>NetBeans 4.1
  1. Go to Tools -> Options.
  2. Under the building folder expand "Compiler Types", right click on "Indirect Ant Compilation" and go to its Properties.
  3. Change the build targets to the following: clean, compileSrc, compileTest
  4. Change the compile targets to the following: clean, compileSrc
  5. Change the Script to the following dir: <nop>CLforJava/build.xml. Make sure the filename remains when you click out, if it does not remain you will have to locate the file by choosing "...". When done, click close.

Now you can compile each class using Build->Compile or simply by pressing "F9"

Configuring Xcode for CLforJava?

The Xcode Integrated Development Environment (IDE)

The Xcode 2.2 and Java 5 require OS 10.4 or greater and can be found at developer.apple.com. Free registration is required.

Note: When downloading Java, make sure to select the version compatible with your machine (Intel or <nop>PowerPC).

How to configure CLforJava? in Xcode

  1. Select File->New Project.
  2. Select "Ant-Based Empty Project".
  3. Type "CLforJava" into the Project Name field.
  4. Delete everything in the Project Directory field, click "Choose...", navigate to the directory in your <nop>CLforJava folder with the build.xml file in it and click "Choose".
  5. In the main project window, click the Action drop down box and select Add->Existing Files... In XCode 2.0, this action is made by highlighting the group in the "Groups and Files" list and then selecting "Project->Add to Project" from the menu bar.
  6. Add build.xml and the following folders to the project: <nop>BuildEntities, <nop>BuildImports, src, and test.
  7. Important: In the next window, make sure that "Copy items into destination group's folder (if needed)" is not checked and that the radio button for "Create Folder References for any added folders" is checked (This ensures that any new files downloaded during a sync with perforce will show up in the project automatically). Click "Add".
  8. Edit the target by expanding the "Target" item in the "Groups and Files" window, then double-clicking the listed target. Now change, under "Custom Build Command," change the arguments field from "emacs $(ACTION)" to "emacs CLforJava? ".
  9. You should now be able to build <nop>CLforJava.

Configuring Xcode for Unit Testing

  1. Move the junit.jar file from "CLforJava/extensions/junit3.8.1" to "/Library/Java/Extensions".
  2. In Xcode, expand "Targets" in the Groups and Files section of the main window.
  3. Control or right click on the target "Main.CLforJava" and select "duplicate".
  4. Rename the new target "RunSmokeTestReports".
  5. Click the "Active Target" drop down select "RunSmokeTestReports".
  6. Select Project->Edit Active Target 'RunSmokeTestReports'.
  7. In the window that opens up, change the Arguments field in the right hand column from "-emacs $(ACTION)" to "-emacs <nop>RunSmokeTestReports" and close the window.
  8. You should now be able to build the <nop>CLforJava test suite.

Configuring <nop>IntelliJ for CLforJava? - an alternative to <nop>NetBeans

Note that <nop>IntelliJ is not currently an official <nop>CLforJava IDE and is therefore not directly supported by the project. However, you may find that it's better than <nop>NetBeans. <a href="http://www.jetbrains.com/idea/index.html">IntelliJ</a> is a fully-featured, professional, Java IDE. Licenses currently cost up to $600, but you can try it free for a month. If this takes off there are free licenses available for classroom use and for open source projects. Below is a detailed guide to setting it up. This guide was made made for Windows, but similar steps should work for other OSs.

Installation and Setup

First download and install <nop>IntelliJ 7.0 from <a href="http://www.jetbrains.com/idea/download/">http://www.jetbrains.com/idea/download/</a>. I used the default settings for installation.

  1. Complete Installation
    1. Open <nop>IntelliJ and you will be asked if you want to import settings. Choose "I do not have a previous..." and click OK.
    2. Choose to evaluate for 30 days or enter a key if you have one.
    3. Accept license.
  2. New project
    1. Click Create New Project Or File -> New Project...
    2. Click "Create Java Project from existing sources" Click next.
  3. Select path
    1. For the Project file location, select the ...\CLForJava\CLforJava directory.
    2. <nop>CLforJava should appear under Name automatically.
    3. Click next.
  4. Select source files
    Leave as is for now (this will need to be setup properly later). Click next.
  5. Library setup
    Leave as is. Click next. If you really wanted to you could combine all of the latest necessary jars into one library.
  6. Module dependencies
    Leave as is. Click next.
  7. Setup JDK
    1. Click the add new JDK button (the box with a plus in it).
    2. Click JSDK.
    3. Select your Java home directory (e.g. c:\program files\java\jdk1.6.0_03). Click OK. (I had trouble getting this to work with Java JDK 1.5. If you choose to use Java 5, you may have trouble during the ant build later on).
    4. Click Next.
  8. Facets
    <nop>IntelliJ will search for, but will not find any, facets. Just click finish.
  9. Loading
    <nop>IntelliJ will load and parse the project. This may take a minute.
  10. Setup source files
    1. Click File -> Settings
    2. Click Project Settings
    3. Click Modules on the left. In the "Add Content Root" pane, click the unmark source button (the little box with the X in it) next to "." under Source Folders. Source Folders should disappear so that all you should see under "Add Content Root" is ...\CLForJava\CLforJava.
    4. In the right pane expand the src directory so that the java directory under it is visible. Right-click on the java directory and then click Sources.
    5. Under Source Folders you should now just have src. Click OK. Click Close.

Configuring and Using Ant

  1. Ant setup
    1. On the very right you should see a bar with the bottom-most button being Ant Build. Click on it. Then click on the Add button (the box with the plus sign in it).
    2. Navigate to ...\CLForJava\CLforJava\build.xml. With build.xml selected, click OK.
  2. Using ant.
    1. In the Ant Build window, click clean and then click the run button (the green play button).
    2. A window will pop up in which ant will show its status.
    3. Once clean is done click <nop>CLforJava and then click run.
    4. <nop>The <nop>CLforJava ant script will run and should let you know that it has completed successfully (possibly with a few warnings).

Debugging

  1. Setting up debugging
    1. In the tool bar, the 4th button from the right should be an arrow pointing down. Click it and choose Edit Configurations.
    2. Press the add new configuration button (the box with the plus in it) and select Remote.
    3. Set the port to 11555. Uncheck Make. Uncheck Display settings before launching. Optionally you can name it.
  2. Debugging
    1. Set a breakpoint (Ctrl+F8). Run <nop>CLForJava in debug mode (java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=11555 -jar C:\CLforJava\CLforJava\build\dist\lib\CLforJava.jar).
    2. Click the debug button (should be third from right on the tool bar) or press shift+F9.

Hotkeys

For helpful hotkeys go to Help -> Default Keymap Reference. One of the most useful hotkeys is Ctrl+Shift+N. It pops up a box in which you can type the name of any file (in the project) to open it.

The Build for CLforJava?

Netbeans 4.1: Once you have finished setting up the new project, select Build from the top menu and click Build Main Project (F11).

Mounting the Correct Filesystem

Make sure you have mounted filesystems correctly as described above ("How To Mount CLforJava? in Netbeans").

Running the build.xml

Begin by expanding the project file under the Explorer[Filesystems] window by clicking on it. The build.xml should be in the sub list (Not the build folder!!). Right click on the build and you should now see Run Target. This will display a list including clean,CLforJava,CompileCompleteLispSource,etc. Depending on what you want to do you will choose different selections. To build CLforJava? start with clean,and then repeat this process and choose CLforJava? . After you have successfully built the project refer to the Running CLforJava? guide.(Located below)

Visted <a href="http://jakarta.apache.org/struts/faqs/netbeans.html">http://jakarta.apache.org/</a> For extra help

Creating a shortcut to a target

You can use the Shortcut to Target template to create a mini-script that serves as a shortcut to a commonly used target. You can also customize the way the target is run. The shortcut can be saved as as a menu item, toolbar button, keyboard shortcut, or project link.

Steps:

  1. Choose File -> New from the main window.
  2. Expand the Ant Build Scripts node, select Shortcut to Target, and click Next.
  3. Specify where you want to place the target and whether you want to customize its Ant code. Click Next to proceed.
  4. Select the target in the Select Ant Target pane. The target must already exist in a mounted filesystem. A shortcut can only point to one target. Click Next to proceed.
  5. Add or change any of the shortcut script's elements, such as tasks or properties. This pane only appears if you selected the Customize generated Ant code checkbox in pane 2.
  6. Use the remaining panes of the wizard to assign the shortcut to a project, toolbar, menu, or keyboard shortcut.
  7. Make sure you do not overwrite any existing keyboard shortcuts. You can view existing keyboard shortcuts by choosing Tools Keyboard Shortcuts. The wizard only shows those steps that you selected in pane 2.
When you have specified all of the necessary information, click Finish. The shortcut is created in the specified locations.

Note: If you want to delete a menu shortcut to a target, open the Options window and expand IDE Configuration, Look and Feel Menu Bar. Then expand the menu that contains the shortcut, right-click the shortcut's node, and choose Delete.

Brought to you by the Build Team, ?making your life easy!?

Running the CLforJava? Project / CLJuiz

Note - These instructions are explicitly for Windows. As long as you can find where the NetBeans build process is putting "CLforJava.jar", these instructions should be easily adaptable to other OS's.


Currently, CLJuiz is the User Interface for CLforJava? . You can either run the CLforJava? or CLJuiz from the command line.

You are going to run the file CLforJava.jar that is in the directory C:\%YOUR_PATH%\CLforJava\build\dist\lib\.

In general, you can use the Java command's - jar option to run a .jar file. For example, say you have a runnable jar file called run1.jar. You can execute it like this: java -jar run1.jar.

Steps for running CLforJava? :

  1. First, build CLforJava? (The \CLforJava\build directory will not exist until you do so).
  2. At the command prompt, type "cd C:\%YOUR_PATH%\CLforJava\build\dist\lib" to navigate to that directory. (Don't type the quotation marks.)
  3. Now type "java -jar CLforJava.jar"
  4. CLforJava? should now be running, and you can now enter lisp expressions at the prompt just like you would with any other interpreter (except for features that haven't been implemented yet).
  5. Type "(exit)" to quit CLforJava.
  6. To make it easier, you can put the two commands above on separate lines in a text editor and save it with a ".bat" extension. Double clicking on the resulting file will automatically open a terminal window and run CLforJava? .

Steps for running CLJuiz:

  1. Repeat steps 1 and 2 in running CLforJava? .
  2. Now type "java -jar -DGui=true CLforJava.jar"
  3. CLJuiz should now pop up, and you can now enter lisp expressions at the prompt in the input area, and click the submit button to execute the expression.

Setting the Project Javadoc in Netbeans

Every source file in the CLforJava project has javadoc comments. To compile the javadoc, run the dist target from the build.xml script. You can link netbeans to view the javadoc.
  1. Go to: Tools-> Javadoc Manager
  2. Click on add folder and add CLforJava\CLforJava\build\dist\doc
To view: Go to: View-> Documentation Indices and click on overview. This will open the browser to view the overview-summary.html. (NOTE- your external browser must be set in Tool->IDE Configuration->ServerAndExternalToolSettings->WebBrowsers->External WebBrowser. Set the Browser Executable to your browser .exe). To find specific class javadoc: Go to: View-> Javaddoc index search and type what you are looking for.

JavaDoc commenting in Netbeans

See http://java.sun.com/javase/6/docs/technotes/tools/windows/javadoc.html#referenceguide for an overview of JavaDocs.

Auto Comment

Using the Auto Comment Tool, you can check if your source code has valid JavaDoc comments and create or edit the comments if necessary. Open the Auto Comment Tool from the Explorer by right-clicking the source file that you want to document and choosing Tools Auto Comment. You can also open the Auto Comment Tool from the contextual menu in the Source Editor. Note: you must have the file checked out in Perforce before the Auto Comment function even appears on the menu bar

Correcting JavaDoc

Available only when there is an invalid JavaDoc comment. Opens the Auto Comment dialog box.

When you are writing your JavaDoc for a specific method or class, Go to tools-> correct JavaDoc to produce a quick correct listing of the parameters and return types for that method. Give it a try!

Use Junit in Netbeans

How To Install and Run Junit using the Command Line Execution

Junit is a great tool for use in both the Netbeans IDE and outsde the Netbeans IDE via command line execution. Junit has three different ui's available to use. The textui outputs to the terminal, the swingui and the awtui provide graphical ui's for exectuing tests.

How do I install JUnit?

  1. First, download the latest version of JUnit, referred to below as junit.zip.
  2. Then install JUnit on your platform of choice:

Windows: To install JUnit on Windows, follow these steps:

  1. Unzip the junit.zip distribution file to a directory referred to as %JUNIT_HOME%.
  2. Add JUnit to the classpath: set CLASSPATH=%CLASSPATH%;%JUNIT_HOME%\junit.jar

Unix (bash): To install JUnit on Unix, follow these steps:

  1. Unzip the junit.zip distribution file to a directory referred to as $JUNIT_HOME.
  2. Add JUnit to the classpath: export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit.jar
  3. (Optional) Unzip the $JUNIT_HOME/src.jar file.
  4. Test the installation by using either the textual or graphical test runner to run the sample tests distributed with JUnit.
    • Note: The sample tests are not contained in the junit.jar, but in the installation directory directly. Therefore, make sure that the JUnit installation directory is in the CLASSPATH.
      • For the textual TestRunner, type: java junit.textui.TestRunner junit.samples.AllTests
      • For the graphical TestRunner, type: java junit.swingui.TestRunner junit.samples.AllTests
      • All the tests should pass with an "OK" (textual) or a green bar (graphical). If the tests don't pass, verify that junit.jar is in the CLASSPATH.
  5. Finally, read the documentation.

Create tests using Junit in Netbeans

  1. In the IDE explorer mount directory ...\CLforJava\test\src\java This is where we store our test classes.
  2. Make sure that ANT has the directory to the junit.jar file. To do this go to tools-> options-> miscellaneous->click Add JAR/ZIP navigate to your junit.jar file and click Ok. Click Ok one more time to save your changes.
  3. In the Filesystem window of Netbeans right click on the java file you would like to create a test class for This is in the CLforJava\src\java dir. Go to tools -> Junit tests -> create test or use the Keyboard shortcut CLT-ALT-J.
  4. In the Create Tests Frame make sure that in the Filesystem box the directory ...\CLforJava\test\src\java is selected and Click OK. The test class application skeleton for your class has been created for you and put in this directory .
  5. Now put in a main to run the test cases. Example:
     public static void main(java.lang.String[] args) {
        junit.textui.TestRunner.run(suite());        
    }    
  1. Add a Fixtures in your test class to run test cases against. Declare any variables needed, then use the setUp method to intialize these variables. Example: (look at the bottom for the setUp method)
    public HelloWorld2Test(java.lang.String testName) {
        super(testName);
    }
    
    public static Test suite() {
        TestSuite suite = new TestSuite(HelloWorld2Test.class);
        return suite;
    }
    
    /** Test of HellowWorld2 method, of class HelloWorld2. */
    public void testHellow() {
        System.out.println("testHellowWorld2");
        String greeting = testObject.hello("Joe");
        assertEquals(greeting, "Hello Joe!");
    }

    //fixture to run tests againsts 
    protected HelloWorld2 testObject;
    
    // setUp intializes protected variables
    protected void setUp(){
     testObject = new HelloWorld2();   
    }

6. Remember, failures are expected, errors are not. If you have not noticed, the framework automatically creates a test method for each method of the tested class with a fail method inside it. Do not remove the fail method unless you write some code of you own to test that method. Notice the assert function in the API for assert. Check the API for spefications of the assert method. the assert is the engine that runs the test.

To run the tests make sure that you recompile any changes made to the tested class. Right click on the test class either in the Filesystem

Topic revision: r86 - 2010-04-21 - 19:32:47 - KitCheng
 
Home
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback