Now my doubt is, a few testcases like withdraw0 are meant not to occur, ie, no 0 withdrawal can be made. Should we consider this as a testcase passed or failed? In this case the above testcase class fails to run on jUnit.
I am quite confused. I hope i havent made it confusing for you guys as well. Kindly help me.
It looks like you are confused. I certainly am now I'm especially puzzled by all the fail("not fail").
For me, unit tests have two jobs:
Enforce correct program behaviour
Explain what correct behavior should be to human readers
While your unit tests seem headed toward the first goal, they don't seem to address the second one at all. This may be where your confusion comes in.
Let's take your "deplosit0" test:
This test isn't really testing anything. Mostly it just prints some stuff out, which requires a knowledgeable person to interpret the output. I really doubt that if you came back to this project a year later you would remember that a printed balance of 300.00 followed by a "not fail" message indicate that a deposit of zero should throw an exception!
I would expect to see somthing much more like:
I have removed the System.out.prints (they don't actually test anything) and replaced them with asserts which will fail if things are wrong.
I have checked the balance before and after the bad deposit, to make sure that (even if the deposit of zero correctly throws an exception) there are no unwanted side-effects.
If I were writing this test suite myself, I'd also probably give that 300 a name e.g.