From leavens@cs.iastate.edu Tue Nov 12 19:02:02 2002 Date: Tue, 12 Nov 2002 19:01:21 -0600 (CST) From: Gary T. Leavens To: Kristina Boysen Cc: Steve Shaner , Seth Bacon , ckilgore@iastate.edu, cs362s@cs.iastate.edu Subject: Re: Problems with JML-JUnit Kristina, On Tue, 12 Nov 2002, Kristina Boysen wrote: > My group has been trying to run our _JML_TestCase files with jml-junit, > and we've been running into runtime errors. We are compiling and running > these off of popeye, and everytime we run it, we get the error that the X11 > window cannot be open. It is probably a misconfiguration. Either you haven't set your DISPLAY variable, or you haven't done the xhost command needed (see the "running Java" web page) or it may be that the jml-junit command is misconfigured (although it looks right to me). > It is trying to open swingui, however, in our code we > specified the either the jmlunit.JMLTestRunner or junit.textui.TestRunner to > run our tests. In both cases we ran across this error. Is there anyway we > can get a text version running? Yes, instead of using jml-junit, just use jmlrac as in: jmlrac my.test.Class_JML_TestCase That should do the trick. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------------------------- From leavens@cs.iastate.edu Wed Nov 13 04:23:06 2002 Date: Wed, 13 Nov 2002 04:19:05 -0600 (CST) From: Gary T. Leavens To: Kristina P Boysen Cc: cs362s@cs.iastate.edu Subject: Re: Problems with JML-JUnit Hi Kristina, On Tue, 12 Nov 2002, Kristina P Boysen wrote: > At 07:01 PM 11/12/2002 -0600, you wrote: > > > >On Tue, 12 Nov 2002, Kristina Boysen wrote: > > > > > My group has been trying to run our _JML_TestCase files with > > > jml-junit, > > > and we've been running into runtime errors. We are compiling and running > > > these off of popeye, and everytime we run it, we get the error that the > > > X11 > > > window cannot be open. > > > >It is probably a misconfiguration. Either you haven't set your > >DISPLAY variable, or you haven't done the xhost command needed (see > >the "running Java" web page) or it may be that the jml-junit command > >is misconfigured (although it looks right to me). > > > > > It is trying to open swingui, however, in our code we > > > specified the either the jmlunit.JMLTestRunner or > > > junit.textui.TestRunner to > > > run our tests. In both cases we ran across this error. Is there > > > anyway we > > > can get a text version running? > > > >Yes, instead of using jml-junit, just use jmlrac as in: > > > > jmlrac my.test.Class_JML_TestCase > > > >That should do the trick. > We would have done the jmlrac, but it complains that there is a > NoClassDefFoundError in the test class. We have compiled the test code > with jmlc, so in theory it should work; I'm not sure what's going on. > I see. You are right tht these tools set up different CLASSPATHS. I think tht it will work if you put everything that jml-junit puts in your CLASSPATH and then run the TestCase class (i.e., it's main). This can be done as follows (on the dept. machines, adjust for home use): $ export CLASSPATH="$CLASSPATH:/opt/JML/bin/jmljunitruntime.jar:/opt/junit/junit.jar" $ jmlrac my.test.Class_JML_TestCase Alternatively, instead of using the jml-junit script that comes with JML, which tries to invoke the swingui for juniti, you can instead make a copy of the jml-junit script and change the line exec java -Xbootclasspath/a:"${JMLDIR}${JFILESEP}bin${JFILESEP}jmlruntime.jar" -mx256m junit.swingui.TestRunner "$@" to be: exec java -Xbootclasspath/a:"${JMLDIR}${JFILESEP}bin${JFILESEP}jmlruntime.jar" -mx256m org.jmlspecs.jmlunit.JMLTestRunner "$@" and then use your copy of the script. The problem might also be that you are using the 3.8.1 version of junit, which doesn't work with org.jmlspecs.jmlunit.JMLTestRunner. If that is the case, use the 3.7 version of JUnit. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------------------------------- From leavens@larch.cs.iastate.edu Fri Nov 15 18:11:46 2002 Date: Fri, 15 Nov 2002 18:03:21 -0600 (CST) From: Gary T. Leavens To: System Support Group Cc: Com S 362 students and staff -- Brian Wicks , Chintaka Ranasinghe , com_s_362@cs.iastate.edu, Matthew L. Canny , Michael Rivera , Sze-Yiing Tan , Tongjie Chen , Tong Siang Chua Subject: Add to the CLASSPATH Hi Dave, et al., Thanks for propogating JML to the other Linux machines. There is a problem to be fixed in the jml-junit shell script that was an error we made in the current JML release. It defines variables PATHSEP and FILESEP, but in a few places it uses "JPATHSEP" and "JFILESEP". If you could please change all occurrences of JPATHSEP to PATHSEP and JFILESEP to FILESEP in the jml-junit script in /opt/JML/bin/jml-junit that would fix one problem. A second problem is that we didn't realize that the CLASSPATH also needs to include some JML jar files when compiling the (_JML_Test.java and _JML_TestCase.java) files generated with JML's jmlunit tool. As a stopgap, could you put /opt/JML/bin/jmlruntime.jar and /opt/JML/bin/jmljunitruntime.jar in the CLASSPATH that students get by default on the Linux machines that have JML? If that's too much trouble, I am (also) going to tell students to do this themselves when they run javac on a jmlunit generated file. But this would help. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------------------------------------- From leavens@cs.iastate.edu Sun Nov 17 20:07:33 2002 Date: Sun, 17 Nov 2002 20:03:54 -0600 (CST) From: Gary T. Leavens To: Daniel Tong Siang Chua Cc: cs362s@cs.iastate.edu Subject: Re: question about hw6 Daniel, On Sun, 17 Nov 2002, Daniel Tong Siang Chua wrote: > Sorry to bother you but I am working on hw6 and I am facing some problems. No problem. > For public boolean equals(Object oth) > I try to do something like this; > > public boolean equals(Object oth) { > if((oth instanceof HistoricalData)) > return true; > else > return false; > > But it seems like not working. > Can you please give me more ideas how to do this? You have to test the value in the true case. Cast oth to a HistoricalData and ask if it has the same properties as "this". > Also, how should we test hashCode since we don't know the exact hashCode. You could, for example, just see that it returns an int (and doesn't throw an exception, for example). -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------------------------------ From leavens@cs.iastate.edu Sun Nov 17 20:08:04 2002 Date: Sun, 17 Nov 2002 20:07:04 -0600 (CST) From: Gary T. Leavens To: Kevin Morrison Cc: cs362s@cs.iastate.edu Subject: Re: cs362 hw6 Hi Kevin, On Sun, 17 Nov 2002, Kevin Morrison wrote: > I am a bit confused about the HistoricalData class. What exactly are we > supposed to add a Double to? Shouldn't there be some sort of collection of > Doubles as a private variable? I must be missing something. I've talked to a > few other people from the class about it, and they don't know either. Any help > would be appreciated. Yes, of course, you'll have to add some private variables; I'm sorry I didn't make that clear in the instructions. A collection would be fine, although I think you can make do with some less heavy-duty fields. But whatever works for you. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------------------- From leavens@cs.iastate.edu Mon Nov 18 04:35:01 2002 Date: Mon, 18 Nov 2002 04:27:25 -0600 (CST) From: Gary T. Leavens To: Kristina P Boysen Cc: cs362s@cs.iastate.edu Subject: Re: Homework 6 Hi Kristina, On Sun, 17 Nov 2002, Kristina P Boysen wrote: > When I initially created the test cases in part a, I ran across the problem > that I cannot access any stored data in HistoricalData because there is no > method to store any information in the class. This causes a problem > because we are supposed to create test cases based on data stored in > Historical Data. Thus, HistoricalDataTest will not compile because it > cannot find the data. Is there any way around this problem? Can I change > Historical Data just enough to have this compile? There are two methods, add and addAll, in HistoricalData that allow measurements to be added to an instance of the classs. So I think you must mean that you need to add private fields to HistoricalData to allow the data passed to either add or addAll to be saved in some fashion in an instance of HistoricalData. Yes, you can certainly do that, and I expect you to add such declarations of private fields to HistoricalData. I should have put some comment in the file to that effect. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------------------- From leavens@cs.iastate.edu Mon Nov 18 04:35:11 2002 Date: Mon, 18 Nov 2002 04:34:25 -0600 (CST) From: Gary T. Leavens To: Kevin Morrison Cc: cs362s@cs.iastate.edu Subject: Re: cs362 hw6 compiling Kevin, On Sun, 17 Nov 2002, Kevin Morrison wrote: > Sorry to bother you again, but I can't even get a skeleton test class > to compile on the department linux machines. I am getting the error > > TestCase() is not public in junit.framework.TestCase; cannot be accessed > > from outside the package > Public class HistoricalDataeTest extends TestCase You need to make the constructor of your class, HistoricalDataTest, look like: /** * Constructor for HistoricalDataTest. * @param name the name of this test case */ public HistoricalDataTest(String name) { super(name); } TestCase does not, indeed, have a constructor with no arguments. You need to have a constructor with a string argument that calls the constructor from the superclass, as above. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------------------------ From leavens@cs.iastate.edu Mon Nov 18 18:50:12 2002 Date: Mon, 18 Nov 2002 18:49:40 -0600 (CST) From: Gary T. Leavens To: Erfi80@aol.com Cc: cs362s@cs.iastate.edu Subject: Re: 362 homework issues (JUnit tests don't fail) David, On Mon, 18 Nov 2002 Erfi80@aol.com wrote: > i'm having trouble just getting my junit test to fail (this is without having > changed the HistoricalData.java source at all). All the test that I created > thru Eclipse pass...and they are all of type void...how are the test methods > supposed to ever fail when they don't return anything? Should I be making > these all boolean tests? and if so, why didn't it do this when I used the > Eclipse wizard? > > otherwise, what am I missing to get JUnit to run correctly? If you have no calls to assertTrue or assertEquals (or fail) in your testing code, then you won't get any failures. These method calls are how junit determines whether things pass or fail. So if the body of your test method looks like the one below testFoo() { T o = new T(); o.foo(7, 2); o.query(3); } then you will get the behavior you describe. It should look more like... testFoo() { T o = new T(); o.foo(7, 2); assertTrue(o.query(3)); assertEquals(7, o.otherQuery()); } See http://junit.org for more about using junit. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------------------------- From leavens@cs.iastate.edu Mon Nov 18 19:05:46 2002 Date: Mon, 18 Nov 2002 19:05:26 -0600 (CST) From: Gary T. Leavens To: Chase Caster Cc: cs362s@cs.iastate.edu Subject: Re: junit testing for group project Hi Chase, On Mon, 18 Nov 2002, Chase Caster wrote: > I'm having trouble figuring out how to make junit tests for my group's > project. Most of the classes, due do the use of the wildtangent graphics > library, require certain objects to be passed from a webpage via javascript. > Another problem is that some of the methods' effects can't be measured > quantitatively. For example, after the constructor for the player class is > called, the player should be in the given world, and able to look and move > around. How would I test something like that with junit? Another example could > be the movement method. It would be possible to check the position and > orientation vectors after the method was called, but that doesn't garuntee that > the player is actually in the right position. This is actually a problem that > we have been having with our code. The updateOrientation method is supposed to > turn the player around in space, and it updates the orientation vector > correctly, but in the game, when you try to turn the player, they are rotated > around the game's axes instead of the player's internal axes, though this > transposition isn't evident in the player's position data member... Is there > some other form of testing we should be using for the game? This is a tough (research) issue. There are two general things you can do. The first is to divide the specification (what you are testing) into correctness and quality issues. Correctness are things you can actually measure and are right or wrong. The quality issues are things you can measure along a scale, and you can do better or worse, but there isn't such a sense of right or wrong. Perhaps the thruput (frames per second is like this). One way to make it possible to have correctness properties is to add add extra (query) methods to some objects, this often lets you test whether things worked or not. These methods may not be necessary for anything other than testing. For example, this idea may work for the updateOrientation method you describe. A test that calls updateOrientation should be able to query the objects (player, space) involved and see if the right axes have been updated as expected. The second thing you may need to do is to use underspecification for quality properties. For things you can't specify, you should just say write a specification of the former part and leave these things you can't specify unsaid (untested directly). To test these unspecified, the best you can do is have test automation that runs the test procedure and lets a human decide if it worked or not. To do this, write a method that asks the human if things look right or not, and log a failure if they don't. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------------------------------------------- From leavens@cs.iastate.edu Tue Nov 19 02:36:50 2002 Date: Tue, 19 Nov 2002 02:36:30 -0600 (CST) From: Gary T. Leavens To: Ryan M. Gerdes Cc: cs362s@cs.iastate.edu Subject: Re: COMS 362: HW06-JML Ryan, On Mon, 18 Nov 2002, Ryan M. Gerdes wrote: > Are we required to write an invariant for all methods? I ask this > because I am having troubles discovering an invariant for the constructor. You just have to write one invariant. An invariant is written once per class and applies to all methods in a class. It describes a property that is true all the time the code of the class isn't executing; that is, the invariant is true when you're outside the code of the class. It isn't that you write an invariant for each method, just have one for the class. To find an invariant, think about what fields you have in the class, and if there are any properties that they should have at all times. Then write those down. For integer variables these properties may be very simple (e.g., comparisons with constants). -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------------------------------------- From leavens@cs.iastate.edu Tue Nov 19 11:08:37 2002 Date: Tue, 19 Nov 2002 11:07:58 -0600 (CST) From: Gary T. Leavens To: ehennis@iastate.edu Cc: cs362s@cs.iastate.edu Subject: Re: Homework 6 Evan, You should read about how clone works in Java and how exceptions work in Java. Briefly, if you want to have Object's clone method do something for you, your type must implement the Cloneable interface. Otherwise you get that exception. To test that you got an exception that you expect to get you should do something like: try { o.m(); fail("o.m() should throw exception"); } catch (NameOfException e) { //success } in a JUnit test. I think I mentioned this in class one morning... On Tue, 19 Nov 2002 ehennis@iastate.edu wrote: > I am having some trouble with my homework catching the exception that > HistoricalData.java is throwing. I am uncertain to what the assertEquals > ( , ) should be set to. Here is my Code for clone() > > public Object clone() throws CloneNotSupportedException { > try { > return super.clone(); > } > catch (CloneNotSupportedException C) > { throw new CloneNotSupportedException(); } > > } > ********************************************************** > and here is my code for the Junit part: > public void testClone() throws CloneNotSupportedException { > HistoricalData His; > His = new HistoricalData(); > > HistoricalData His2; > > assertEquals(new CloneNotSupportedException(), > (HistoricalData) His.clone()); > > His2 = (HistoricalData) His.clone(); > > assertEquals(true, His.equals(His2)); > > } > ********************************************************** > Do you have any thing that will help me?? -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------------------------- From leavens@cs.iastate.edu Wed Nov 20 15:56:22 2002 Date: Wed, 20 Nov 2002 15:50:07 -0600 (CST) From: Gary T. Leavens To: Kevin Morrison Cc: cs362s@cs.iastate.edu Subject: Re: jml postcondition error Hi Kevin, Sorry I was in a rush before. As I mentioned, if you get an exception in an assertion, for example, iif min() throws an exception in min() == (...).min() then JML counts this as false. The reason is that in the logic the JML uses, and expression of that is undefined (for example because of throws an exception) has an arbitrary value of the expression's type. So JML is allowed to substitute different integers for these two method calls, and the run-time assertion checker essentially does that, making the above into something like, say, 1 == 2 which is false, hence the assertion failure. The reason your code itself does not to this is because of the following statements: > if(size()==0) > { > if(h.size()==0) > return true; > else > return false; > } which means that the code never gets to calling min, max, and average when the size is 0. So in summary the problem is just in your assertions, not in the code. This is not uncommon; I find that about half of the errors that I find using the run-time assertion checker are errors in the assertions. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------------------------------------------------- From leavens@cs.iastate.edu Tue Dec 10 21:51:17 2002 Date: Tue, 10 Dec 2002 21:45:56 -0600 (CST) From: Gary T. Leavens To: Evan Mikel Hennis Cc: cs362s@cs.iastate.edu Subject: Re: More Java Problem Evan, On Tue, 10 Dec 2002, Evan Mikel Hennis wrote: > This java is driving me nuts. > I have all of the correct files on my CS account. I am running on popeye > from my house off campus. I set the classpath like you told me in class. > Which is %setenv CLASSPATH ~ehennis/cs362:$CLASSPATH Then I copied all of > the files into the directory ~ehennis/SyllaTrak/SyllaTrak/*.java then I > ran the command %javac SyllaTrak/*.java from the directory > ~ehennis/SyllaTrak. And it complied fine and game be the .class files. But > then from the same directory I tried to run %java Syllatrak.SyllaTrak but > then I got the noclassdef error. What in the world am I doing wrong?? You put ~ehennis/cs362 in our CLASSPATH, but that isn't right if your package is in the directory ~ehennis/SyllaTrak. If you have it set up that way, you need to use %setenv CLASSPATH ~ehennis/SyllaTrak:$CLASSPATH I meant the "cs362" directory as an example. It's the actual name that matters. Let me know if this works... -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------------------------- From leavens@cs.iastate.edu Tue Dec 10 21:51:34 2002 Date: Tue, 10 Dec 2002 21:50:54 -0600 (CST) From: Gary T. Leavens To: Kevin Morrison Cc: cs362s@cs.iastate.edu Subject: Re: JUnit testing for Bounty Hunter Project Hi Kevin, On Tue, 10 Dec 2002, Kevin Morrison wrote: > It seems our group is at the end of our rope for doing JUnit testing for > the classes in our project. As you probably know, our project is run > through a web page that has an object of type wt (wildtangent). This > object is necessary to run many of our classes and thus is necessary to > do JUnit tests on those classes (I have written jml for them however). > I have been pondering this problem quite a bit lately, but I can't quite > put my finger on how to solve it, as my experience is very limited in > this field. The only thing I can think of that might possibly work is > to make a dummy web page that contains this wt object and have the test > class extend Applet. I have no idea if that would even be a reasonable > solution. Can you help me out here? Will that work or is there another > solution you could think of? Otherwise, we're kind of stuck. I think it's okay to test only the classes that fit into the kind of testing that is easy with JUnit with JUnit (simple ADTs that don't use the wt stuff), and to test these kind of classes manually (not using JUnit). While I'm sure that, in principle, it's possible to use JUnit, perhaps as you hypothesize, to do the testing, I didn't intend for it to be extrodinarily difficult to use JUnit, and it sounds quite difficult for at least some of these classes. For such classes, just don't use JUnit if it's too hard or too expensive. Considering cost is an important part of software engineering; it's not worth doing if it's too expensive. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------------------------------- From leavens@cs.iastate.edu Sun Dec 15 21:59:09 2002 Date: Sun, 15 Dec 2002 21:58:40 -0600 (CST) From: Gary T. Leavens To: evan@evanrothmayer.com Cc: cs362s@cs.iastate.edu Subject: Re: Final Presentation Monday at 9:45 Hi Evan, On Sun, 15 Dec 2002 evan@evanrothmayer.com wrote: > We were wondering if you could make your laptop available along with the room projector > tomorrow so we can present our class diagram using it. (It seems necessary, since our diagram > is rather crowded relative to an 8.5 x 11 sheet of paper). If that will not work, please > respond quickly and we will try to print out a larger version. Also, please let us know if > you have internet access or not, so we know whether we can download it, or to bring a CD or > floppy or something. Thanks very much! I'd rather not, simply because there just isn't enough time to switch different groups. Can you just give us an abstraction of your class diagram (the important/interesting bits)? Don't draw any methods or fields either. If you'd like, send me a PDF or postscript file, and we can have it copied on to a transparency for overhead projection, however. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ------------------------------------------------------------------