• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

why does junit create a instance of the testcase class each time it wants to execute testXXX()

 
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am new to Junit and have been reading up on the tutorials I understand that junit creates a instance of the testcase class each time it wants to execute testXXX() method, I was wondering why ?? Why not just create one instance and then execute

1) setUp
2) testXXX
3) teardown

in the above order for each testXXX method ?

and I also I read that it uses a collecting parameter design pattern to fill in the TestResult object with the test results, It uses the collecting parameter design pattern to collect the output of the multiple methods it executes, (This is what I have understood from the text I have gone through)

The text I was talking about

The Smalltalk Best Practice Patterns (see Beck, K. Smalltalk Best Practice Patterns, Prentice Hall, 1996) has a pattern that is applicable. It is called Collecting Parameter. It suggests that when you need to collect results over several methods, you should add a parameter to the method and pass an object that will collect the results for you. We create a new object, TestResult, to collect the results of running tests.



Now my question
if each testXXX is executed through a different instance how does it collect the results ??

My questions are inter linked I sort of feel that I am misunderstanding something here !



Thanks in advance
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sid,
1) I like this behavior as it doesn't allow the tests to interfere with each other across runs. I use a lot of instance variables and certainly don't null them all out in the tear down.

2) The framework remembers it. I think I'm not understanding this part of the question.
 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I did edit my previous post so that it becomes more clear, Just letting you all know

Thanks
Sudarshan
 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

This is the answer for my own question , just putting it here in case some one else finds it usefull.

Now if each test case method is executed through a different instance how does it collect the results? By using the Collecting Parameter pattern of course!

Like I said before, a TestSuite is created with different instances of your TestCase class each executing a different test case method. It is your TestSuite that makes use of the above pattern and passes a TestResult object as a parameter to every TestCase it runs to collect the results.
 
Jeanne Boyarsky
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sid!
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic