File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes JUnit inclusions, yes or no? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "JUnit inclusions, yes or no?" Watch "JUnit inclusions, yes or no?" New topic
Author

JUnit inclusions, yes or no?

Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
I'm trying to be a good dooby and test everything with JUnit. Sometimes I uncover issues while setting up the testing that cause me to alter my thoughts on the design. Part of the project requirements are for us to document our design decisions. I'm starting to think that maybe I should be including the test materials and a junit.jar file, since they have played a fundamental role in the project.
Any opinions? Does this seem like a practice that would tick a Sun marker off? (e.g. "why are you including an open source jar with your project; you didn't write that code! And what the heck is all this test stuff doing here in the first place?")
Inquiring minds want to know.


Reid - SCJP2 (April 2002)
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

I was wondering pretty much the same thing.
My plan was to just jar the unit tests and make a reference to in the readme or some other part of the documentation under a clearly marked section, e.g. "Unit Testing Strategy". I didn't plan to include the JUnit file- just a note of the version of JUnit that was used. The idea is to leave a trail of breadcrumbs for future maintenance programmers.
I don't see a problem with doing this as it doesn't really affect the actual running of the application by the Sun marker. I could be wrong though.
Any comments on this plan?
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
Wow, I hadn't even thought about including test results. The assignment says "You are not required to develop your code using any particular implementation of the Java 2 platform, but the submission that you return <i>must have been tested and shown to work under a production (not development) version of the Sun Microsystems' Java 2 platform</i>". Is Sun expecting us to send documentation of our testing strategy and our test results?
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
Originally posted by Junilu Lacar:
I didn't plan to include the JUnit file- just a note of the version of JUnit that was used. The idea is to leave a trail of breadcrumbs for future maintenance programmers.
...
Any comments on this plan?

I like this idea. The information is complete. The marker has what he needs, but nothing he doesn't really need. The submission doesn't get bloated by another jar (there was info from Sun when I signed up for this that you should try to keep the uploaded materials below 1 meg).
Originally posted by Robin Underwood:

Is Sun expecting us to send documentation of our testing strategy and our test results?

Well, I don't know what they are expecting, that is the problem. I know when I write requirements documents they are a heck of a lot more specific than what Sun gives us, and I'm inclined to think that is part of the "test". It is a real-world situation to have something that purports to be a requirements document but to have a lot of holes in it.
What I did was document all the assumptions I felt I needed to make before beginning the project; essentially applying the philosophy that QA people use - if you've been asked to test something, but don't have a requirements doc, your first job is write a requirements doc.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Can't guarantee this but I think they will say.
why are you including an open source jar with your project; you didn't write that code! And what the heck is all this test stuff doing here in the first place?")

Meaning I have seen 155/155 grading and they did not send in test results or a JUnit jar file.
If you use JUnit and it helps great, but you don't have to let them know that you used it. And it won't get you extra points for being a good person for using it.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
Mark,
Thanks again for your valuable advice and from keeping me from swerving off onto another detour!
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4462
    
    6

Mark,
Thanks for the advice. I guess I'll just leave the JUnit stuff out then.
Melinda White
Greenhorn

Joined: Jun 19, 2002
Posts: 25
I have the very same question. For me it's not just a matter of excluding my Junit test files. I also a couple of mock objects (and code that calls them(MockDataAccess for example) and lots of acceptance test code as well.
I also tested add and remove record and modified invariant() to get more info on deleted records - again, for multithreading testing purposes.
Mark, will I be docked for this? Do I need to remove this method and all add record, remove record code? (Even if simply exlcude my unit test files, my code as it stands now, has been slightly modified for testing purposes.)

Sometimes Junit requires that you make a particular method public so I guess that will have to be modified or explained?
Also, I have some convenience mehtods for testing only - like "dumpMap" "clearAllLocksNoWait", stuff like that.
So I guess the upshot I need to clean up my code and remove all evidence of testing???
Any response would be greatly appreciated. I think, the way I've been trained (XP) - it's an integral part of the code.

Thanks,
Melinda
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi Melinda,
I suggest that you extract your source from the JUnit when you submit: let the code's quality speak for itself.
M


Java Regular Expressions
Melinda White
Greenhorn

Joined: Jun 19, 2002
Posts: 25
Thanks Max,
Do you think that I should rip out all my helper methods and even the overridden invariant method in my DataExt class? This method is overriden so I can print out deleted record count. I used this a lot for a couple of multi client acceptance tests.
Thanks for any feedback.
Melinda
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
I think so, yes. I'm a big XP proponent myself, but I don't think that the production ready code should any methods that were there only for testing. Without looking @ the code, I wonder if it would be possible to use your toString() for debug message, or maybe even log the deletion of records?
All best,
M
Melinda White
Greenhorn

Joined: Jun 19, 2002
Posts: 25
Thanks Max
Burk Hufnagel
Ranch Hand

Joined: Oct 01, 2001
Posts: 814
    
    3
Originally posted by Melinda White:
... Sometimes Junit requires that you make a particular method public ...

Melinda,
I'm curious as to when this occurs? I'm using JUnit and I haven't run into such a situation -- yet.
Thanks,
Burk


SCJP, SCJD, SCEA 5 "Any sufficiently analyzed magic is indistinguishable from science!" Agatha Heterodyne (Girl Genius)
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, if you want to test a method, your JUnit test case needs to be able to access that method. This needn't require a public method though, if what you're testing shouldn't really be public. You can make a package-access method, and then make your test case part of the same package. Note that it can be in the same package but a different source tree, so that when you jar up your submission you can eaily omit the test classes whose source is elsewhere. E.g. my directory structure includes
src/suncertify/db/Data.java
test/suncertify/db/DataTest.java
When testing I compile all files in the src tree and test; for my submission I will use only the stuff in src.
In general I try to avoid testing any methods not explicitly part of the public API of a class (which for me would include public and protected methods, but usually not package or final) - and for Developer Cert I'm extra inclined to follow this approach since we constantly hear we should keep things simple. But if you do want to put in non-public methods for testing, it's not difficult to do, as shown above.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JUnit inclusions, yes or no?