File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Help please with complex JUNIT test cases across classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Help please with complex JUNIT test cases across classes" Watch "Help please with complex JUNIT test cases across classes" New topic
Author

Help please with complex JUNIT test cases across classes

Hussein Patwa
Greenhorn

Joined: May 07, 2008
Posts: 5
Hello,

I have been thrown rather into the deep end and asked to debug and create test cases for an application. I'm completely new to JUNIT, and I'll be honest my Java is not that great beyond the basics. I know the methods I want to test, and the results I want to prove. However, it's the coding that is the problem for me. I learn best by example rather than by explanation, and I also suspect the fact I'm partially sighted is not helping issues when it comes to spotting errors. The application itself is at Index of /trending

That folder also contains my checklist of things to test and an explanation of the classes in the application. I've looked for quite a while at JUNIT examples, and even had someone send me an application with test cases, but I was having real problems relating any of it to my application. It's not helping that to test any of the classes seems to require taking arguements and items (arrays, files, ints, etc) from other classes, and here I'm totally lost.

I'm not asking for someone to do this all for me, but I'd be really grateful if someone could possibly take a look at this and perhaps get me started on the right track with a couple of examples with my application. Thanks very much, Hussein
Paul Michael
Ranch Hand

Joined: Jul 02, 2001
Posts: 697
Where can we see this "trending" folder of yours?

Thanks.


SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
Hussein Patwa
Greenhorn

Joined: May 07, 2008
Posts: 5
I'm so sorry! The html tags musthave been stripped at some point.

www.patwanet.co.uk/trending

Thanks again for your time.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
It is a fact that writing JUnits often requires spending a lot of time in creating test data. If you need an input String array, then create the array, populate it with test data and run the test (which would often include assertions on the results of the test). It is best to start by doing a small test and then gradually doing more complicated tests.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I'd like to take a look, but I don't seem to have permission to access the zip file.

Anyway, if I'd had to, I'd bet quite a sum that the code you are asked to test is not being written with testability in mind. Often it's quite painful to work with such code.

Are you allowed to change the code?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Hussein Patwa
Greenhorn

Joined: May 07, 2008
Posts: 5
Thanks for your posts and tips. I'm really starting to hate file permissions and everything to do with them. Don't know why my website has suddenly started marking every file as owner access only, when it didn't used to do that. And I'm pretty sure I haven't changed anything for the simple reason I'm not advanced enough to do that (still on the learning curve, I'm afraid). Anyway, it should work now for all. Thanks again.

Oh, and yes, I'm allowed to change the code. Just as long as it works and has tests to prove it works.

H.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Hussein,
It's good you are allowed to change the code.

The first requested test in tests.txt is "Test the file data.csv is actually found ". This is actually easiest to test if you access the file system by creating a test file and reading it in. And also to point to a file that doesn't exist. While this isn't a unit test in the true sense of the word, I personally would rather have tests before doing a bigger refactoring.

Also, what is supposed to happen if the file isn't found? Right now the class fails silently which isn't good.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help please with complex JUNIT test cases across classes