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
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.
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
Joined: May 07, 2008
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.
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.