• Post Reply Bookmark Topic Watch Topic
  • New Topic

Number of testcases to be written for a TDD using Junit  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please tell me how many test cases one should  write in a TDD using Junit?I was asked this question in an  interview.

Many Thanks.
 
Marshal
Posts: 59458
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You have arrived in the wrong forum; this location is for discussing the website. I shall try moving you to the jobs forum because the answer to that sort of question isn't a number.
I am going to ask you how you answered that question. And did you get the job?
 
Ar Arnair
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

You have arrived in the wrong forum; this location is for discussing the website. I shall try moving you to the jobs forum because the answer to that sort of question isn't a number.
I am going to ask you how you answered that question. And did you get the job?



Many Thanks.I have answered like I have to write as many testcases as possible.I am not sure whether its correct or not as I am new to TDD.I am waiting for their feedback.
 
Sheriff
Posts: 12103
197
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"As many as possible" would not be an acceptable answer to me. Think this over again and post what you come up with.
 
Marshal
Posts: 5804
401
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ar Arnair wrote: Can anyone please tell me how many test cases one should  write in a TDD using Junit?


I think that's the question, which has no answers suchs as: 1, 5, 10, 15, 20, as much as possible...

Now, that they asked such question, you probably wrote in your CV that you know, you do TDD. And if you actually don't - that was your mistake.

Of course! you should test your code thoroughly, but that has nothing to do with TDD as such. That is probably more to do with JUnit, but again, that is just framework which helps you to do that, but has no direct impact on how many test cases you must write. You can write 1, you can write 100 if you want - no difference for JUnit itself.

TDD you could describe as a framework of thinking (stole phrase from Junilu's post 1.25 years ago), which helps you understand/clarify you understand the requirements beforehand of actual implementation. In more expressive words, it helps you to ensure the meadow is the one you need to trample. How many test cases it requires to write? As much as you get it requirements in full so you could implement project to satisfy its requirements as well as have actual evidence it works as specified.

Questions are open and closed. I believe the question given to you was open, which required your thoughts about testing, rather than dry number of test cases required. In fact I don't think you could know the amount of needed tests cases beforehand in any scenario, either simpler or more complex.

And I don't think you can be elaborative enough talking about TDD if you never did it yourself, or probably more correct would be to say, if you don't practice it continuously, or in other words - all the time.
Probably you could read 10 books about it, but if you never did it yourself, interviewer would see it instantly, simply by listening your emotion of talk when you talking about it.

I'll be watching this thread as will be willing and can't wait to see Junilu's thoughts (no pressure) on OP's topic.
 
Marshal
Posts: 4425
283
Clojure IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best advice I've ever received on this topic is from a software trainer in my local developer community. When asked:

"How much testing is enough?"

he would reply:

"Test until the fear goes away"
 
Junilu Lacar
Sheriff
Posts: 12103
197
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Cooke wrote:"Test until the fear goes away"


That's a great way to state something that's very difficult to quantify.

On the flipside of fear is trust. If you don't trust the code or if you don't trust others to keep the integrity of the design, write one or more tests that will fail if the design integrity is compromised. One example is when you're designing for inheritance (see the guidelines given by Joshua Bloch). Another example are getters and setters. I don't usually test these methods unless they do something more interesting than simply assigning a value to a field or returning that field value.

One thing that builds trust in code is cleanliness and clarity. If code is clear and clean and you can easily understand what it is doing, then tests will complement that by giving concrete proof that the code is doing what it says it does. From there it becomes a virtuous cycle of trust. Lacking these characteristics, your code and design can quickly get caught an opposite vicious cycle, where unclear and dirty code makes writing tests for it more difficult and making the whole program less trustworthy.
 
author & internet detective
Marshal
Posts: 38394
650
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ar Arnair wrote:Many Thanks.I have answered like I have to write as many testcases as possible.


Wouldn't that be close to infinity. For example, suppose i am testing a method that adds an array of integers. I could test

  • null array
  • empty array
  • array with one element set to 0
  • array with one element set to 1
  • array with one element set to -1
  • array with one element set to 2
  • array with one element set to 2

  • ...

    See the problem? How do you decide which of these to test?
     
    You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
    Why should you try IntelliJ IDEA ?
    https://coderanch.com/wiki/696337/IntelliJ-IDEA
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!