P05 CISC474 07S-JUnit and Ant

JUnit is a set of Java Classes that allows you to do automated unit testing of Java Software. Automated unit testing is a "big deal" in many real-world Java software development shops these days.

Ant is a tool similar to Makefiles, oriented towards Java. Ant is also a big deal in many real world Java shops.

What you need to do today

Step 1: Divide into two "pairs"

Here's a "default" division, but you may tailor this to your groups needs (e.g. if someone is absent)

Step 2 (JUnit): Get familiar with JUnit and Ant

In your pairs, gather 1 or 2 programmers to a laptop, and start familiarizing yourself with JUnit.

  1. If you have two people to a laptop, pick one person to "drive", and a second person to look on and watch, and guide the process.

  2. First, read over the beginning of the article JUnit Test Infected: Programmers Love Writing Tests which is also available via a local link. Read just far enough that you start getting into code.

  3. At that point, stop, back up a bit, and look at my article topics/java/junit/gettingStarted/gettingStartedWithJUnit.txt. This includes information on how to start working with JUnit on strauss (I'll try to get it installed on Porsche soon.) Do the steps needed to configure the strauss account of the person "driving" for JUnit.

  4. Work through the "Money" example. The code is in topics/java/junit/gettingStarted/money on the course web site, which is also available directly on the strauss file system as the following directory:

    /www/htdocs/CIS/474/pconrad/06S/topics/java/junit/gettingStarted/money

    In that directory, among other things, you'll find a file called build.xml. If you are familiar with using Makefiles under C/C++, then this file is the same kind of thing. However, instead of using Make, it uses a system called Ant. So, that means you need to start learning about Ant as well. Ant helps you automate the process of compiling your Java web app.

    So you should probably go ahead and read up on Ant, and configure your account for use with Ant also. Resources on Ant are in topics/java/deployment/ant

  5. Once you are comfortable with how Junit and Ant work, you are ready for the next step.

Step 3: Once you think you've gotten the hang of JUnit, test your understanding:
Start writing test cases for your Model class of a Scheduling app

What Scheduling App?

Go back and look at P03.html

Also look at the work you did:

http://copland.udel.edu/~gevers/cisc474/P03_G01.html
http://copland.udel.edu/~cwimbrow/cisc474/P03_G02.html
http://copland.udel.edu/~mdwarner/cisc474/P03_G03.html
http://copland.udel.edu/~estein/cisc474/P03_G04.html
http://udel.edu/~zachk/cisc474/P03_G05.html
etc...

You'll see that we started with some input—e.g.

Phill Free: MWF 8a-10:10a, 11a-1:25p, 3:20p-5p
Free: T 8a-9:30a, 10:45a-2p, 3:20-5p
Free: R 8am-9:30a, 10:45a-5p
Gowri Busy: M 9:05a-12:05p, TR 10am-2pm
Scott

Free M,F: 8a-5p
Free: TR 1p-5p
Free: W 8a-9:05a, 12:05p-5p

Matt Busy: MWF: 10:10p-12:05p, 1:25p-2:15p
Busy: M: 5p-5:50p, W: 3p-4p
Busy: TR: 11a-12:15p, T 1:30-2:30p

and

p=Phill, g=Gowri, s=Scott,m=Matt

and then produced some output:

Start End Sun Mon Tue Wed Thu Fri Sat
08:00a 09:05a   pgsm pgm pgsm pgm pgsm  
09:05a 09:30a   psm pgm pgm pgm pgsm  
09:30a 10:10a   psm pgm pgm pgm pgsm  
10:10a 10:45a   s gm g gm gs  
10:45a 11:00a   s pgm g gm gs  
11:00a 12:05p   ps p g p pgs  
12:05p 12:15p   pgsm p pgsm p pgsm  
12:15p 01:00p   pgsm pm pgsm pm pgsm  
01:00p 01:25p   pgsm psm pgsm psm pgsm  
01:25p 01:30p   gs psm gs psm gs  
01:30p 02:00p   gs ps gs psm gs  
02:00p 02:15p   gs gs gs psgm gs  
02:15p 02:30p   gsm gs gsm pgsm gsm  
02:30p 03:00p   gsm gsm gsm pgsm gsm  
03:00p 03:20p   gsm gsm gs pgsm gsm  
03:20p 04:00p   pgsm pgsm pgs pgsm pgsm  
04:00p 05:00p   pgsm pgsm pgsm pgsm pgsm  
05:00p 10:00p              

Imagine that you have a MVC-based web app to solve that problem—i.e. take that input, and produce that output.

Now focus on just the Model part. Imagine that you've already written these classes—and write the test cases for these classes.

Say what?!!?! We haven't even written these classes yet!?!
And you want us to write test cases!?!

Yup. That's exactly what I'm saying.

I know it may seem crazy at first, but that's what "test-driven development" is all about. The idea is that you write the test cases first, and then write the class. This has certain implications:

What test data should I use?

Start with your test data from your P03 web page.

Stories, unit testing... what is all this stuff?
Does this have anything to do with the real world?

If you want to know more, try typing just that set of keywords (i.e. stories, unit testing, pair-programming) into a search engine and see what comes up. Also, check out these ads from a recent issue of a trade magazine.

Your deliverables for P05 (due one week from today, March 19, by 11:55pm).

One member of your group should submit, on WebCT, a gzipped tar file or a zip file containing a directory called P05 that contains Java code. In this directory, include a build.xml file for use with Ant that compiles your code, and runs JUnit tests on it. It's ok if for now the tests fail (i.e. because the body of your methods are all in stub form.)

Next steps beyond that

Upcoming assignments will turn this all into a working web app—here's a preview:

Grading: 100 pts

Item Explanation Point Value
Choice of object Choose an object that could reasonably be expected to be part of the "model" for an MVC app that solves the "find common free time" problem. 10
Choice of methods Design that object with methods that are reasonable, given that objects eventual function within the application 10
Choice of tests Choose reasonable tests that cover the basic functionality of the methods specified for the object 10
Header comments Each file has a header comment indicating the filename, purpose of the file, and the authorship.

For this assignment, this may be any kind of comment a regular comment, or a Javadoc comment—since this requirement was not specific, but rather a "common sense" thing that we would expect every student in a CISC4xx-level course to know, we will be rather "broad-minded" in interpreting this rubric.

Starting with the next assignment, follow the Javadoc style guideline on the Wiki for these header comments.
10
Internal comments Each file is well commented with internal comments explaining what the code is doing. 10
Submission structured as a .tar.gz or .zip file Submission should be structured as a .tar.gz file or a .zip file. (10 points)

(-5) if you submit a tar file that isn't gzipped—the instructions were specific on that point.

(Note that I did tell one group that a jar file was acceptable, so that group is "grandfathered"—no deduction this time for that. For next time though, source code should go in a .zip or .tar.gz file. Jar files are for compiled .class files, not for source code.)

Also, when untarred or unzipped, the result should be a single directory, not a "bunch of files".

Note: deduction for this will be minor—only 3 pts this time—since this requirement was not explicitly spelled out, but was—again—something we'd expect CISC4xx-level students to know. Going forward, this will be a requirement. (See the new Wiki page "General Submission Standards".)
10
Tests fail not pass!

(i.e. you have written stub methods, not working methods)

Where possible, for this assignment, all your methods should be stub methods, so all your tests should fail.

One exception is that if your method returns boolean, there are only two possibilities for what you can put in your stub, so in this case, you might find that some of the tests "inadvertently pass". Exceptions of this nature (i.e. ones that can't be helped) are acceptable.

If all your tests pass, then you missed a crucial point of this assignment—namely that in test driven development, the tests MUST FAIL before they pass, and you need to establish this. If you think that making them pass on the first go around, means you are ahead of the game, then you are mistaken. If you don't ESTABLISH that the tests FAIL when the code is wrong, then you can't depend on the tests!

Making them pass is the next step—and you should have made a whole other directory for that—so that you can submit that as your P06.

Since some of you may not have been 100% clear on this point, I will allow you to make up these 10 points by resubmitting your P05 along with your P06 submission. Submit two separate tar.gz or .zip files. Upload them separately to WebCT—one called P06.tar.gz or P06.zip, and the other called P05.tar.gz or P05.zip. In P05, all the methods should be stubs, and all the tests should fail. In P06, all the tests should pass.

10
Use Ant There should be a build.xml file in the submission that will compile your code when it is unpacked. 10
General correctness,
style, and following instructions
  20
Total   100