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
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 !
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.
author & internet detective