Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help please with complex JUNIT test cases across classes

 
Hussein Patwa
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 697
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where can we see this "trending" folder of yours?

Thanks.
 
Hussein Patwa
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Hussein Patwa
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33667
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic