Computer Science 507
Software Engineering
Spring 2015, The College of Saint Rose
You may work alone or in groups of size up to 4 on this lab. Only one submission per group is needed.
Getting Set Up
Create a document where you will record your answers to the lecture assignment and lab questions. If you use plain text, call it "lab6.txt". If it's a Word document, you can call it whatever you'd like, but when you submit, be sure you convert it to a PDF document "lab6.pdf" before you submit it.
Guest Speaker Reactions
Note: this portion must be done individually and is graded separately.
Participate in the discussion of this week's speaker, Roddy Collins, on the speaker blog. To earn full credit, you should make at least 3 comments on this week's post or replies to comments (at least 1 should be a reply, and at least 1 should be posted within the day following the talk). Comments may address any aspect of the speaker's presentation, including how it relates to topics from other parts of the class. You are welcome to start this process during the talk, if you wish. (5 points)
Lecture Assignment Questions
We will usually discuss these questions at the start of class on the lab due date, so no credit can be earned for late submissions of lecture assignment questions.
Unit Testing
Unit testing is a standard technique for many software development projects. The idea is to develop test cases along with the actual code to make sure the code not only works correctly when first written (at least as far as these tests are concerned) but also that it continues to work (again, at least in so much as it still passes the unit tests) when it is later modified.
There are many techniques, including libraries and frameworks, to support unit testing in nearly any production programming language. As the majority of you are most likely familiar with Java, we will experiment with unit testing in that language. If you are not a Java programmer, be sure to team up with someone who does have some Java experience. Fortunately, the techniques are similar with other languages and unit testing frameworks.
JUnit Introduction and Setup
JUnit is a framework to manage test cases for Java classes. The idea is that for a Java class you wish to test, you write an additional class to perform the unit tests.
JUnit is often used with the Eclipse IDE, but can be used on its own or with other IDEs as well. You are welcome to complete this lab with any IDE you wish, but the instructions will assume you are running Java from the command line on mogul.strose.edu. If you wish to use JUnit in a different environment, you will need to set it up as appropriate.
To set up the Java environment on mogul to include the JUnit jar files. There is a script you can run to do this:
. /home/cs507/junit/junit.bashrc
Note: in the above, the period and space are part of the command and are important!
You can either enter this each time you log into mogul and wish to use JUnit, or you can add it to the end of the .bashrc file in your home directory.
Please copy the files SuperSimple.java and SuperSimpleTest.java from /home/cs507/junit into a directory for this lab. These are an incredibly simple Java class and its corresponding JUnit test class. Take a look at these files and make sure everything in them makes sense (there's not much).
To compile these, the following commands should work:
javac SuperSimple.java javac SuperSimpleTest.java
You can then run the unit test with the following:
java org.junit.runner.JUnitCore SuperSimpleTest
Now, change the isItSimple method so it no longer "works" (i.e., it doesn't return true) and recompile and rerun the test.
This example uses one kind of JUnit assertion, but there are many more.
These kinds of tests work for many simple situations.
More Substantial Tests
Thinking about that ArrayList example, you will quickly realize that many tests will require some "set up" before and/or "tear down" after each test case. JUnit provides this capability with the @Before and @After annotations. The test method annotated with @Before will run before each test method (i.e., those annotated with @Test) and the @After method will run after each (whether the test succeeds or fails).
Note that you will need an additional import for each of these:
import org.junit.After; import org.junit.Before;
Submitting
Before 6:00 PM, Monday, March 16, 2015, submit your lab for grading. Package up all required files into an appropriate archive format (.tar.gz, .zip, and .7z are acceptable) and upload a copy of the using Submission Box under assignment "Lab6".
Grading
This assignment is worth 35 points, which are distributed as follows:
> Feature | Value | Score |
LA 1: (8.2) | 1 | |
LA 2: (8.3) | 4 | |
LA 3: (9.2) | 3 | |
LA 4: (9.9) | 2 | |
Question 1 (SuperSimple output) | 1 | |
Question 2 (SuperSimple output when "broken") | 1 | |
Question 3 (ArrayList test) | 5 | |
Question 4 (ArrayList improved test) | 6 | |
Question 5 (New Java class and corresponding JUnit tests) | 12 | |
Total | 35 | |