Objective
This guided exercise is a good introduction to creating and coding a simple Java project in Eclipse, as well as creating and running JUnit test cases.
Instructions
- Follow the guided instructions in the video above to create a (Java) project with your
Java class and (JUnit) unit test in Eclipse.
- If you've installed the latest Eclipse and Java, the JUnit package is going to be at
version 5, not version 4 as in the video. Don't worry about this. The example steps
will work fine with the latest updates. Do not roll back to version 4.
- Add or edit your comments. At a minimum, each file and class and each method should
have javadoc style comments as follows:
- In the Eclipse editor, add a line above the class declaration ("public class
JunitTesting").
- On that new blank line type: /**[return] (forward
slash, asterisk, asterisk)
When you hit the return key (after those
3 characters, Eclipse will create the comment block for you.
- Inside that new comment block, add a sentence or two with a description of what
is in the file and the purpose for the class.
- Add another line inside the comment block and add the tag "@author" with your name.
It will probably autocomplete when you start typing.
- Below that, add a line with a @version tag. For our purposes, you can use
YYYY.MM.DD.nnn. For example, @version 2021.07.04.004 indicates the file was
updated on July 4th, 2021 and was my 4th build on that day.
- Just above each of your methods, in all of your .java source files, add a comment
block as before. This time, Eclipse adds the @param and @return tags. Above those,
add a sentence describing the purpose for the method and then describe the parameters
and return values for the method on the appropriate comment lines.
-
Archive your project to a zipfile to submit. Right-click the project name from the Package
Explorer and choose Export from the menu. You can also select the project name and use the
File > Export menu item. Expand 'General' and 'Archive File'. Use the Browse button to
specify and name and a destination for your zip file.
- (optional) If you have access to another computer, try copying your zip file there, unzip
the project and then import the project into Eclipse. I like to test my code on Windows and
macOS before publishing content.