This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does JUnit create a new instance of a class each time it calls a test method?  RSS feed

 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am asking this question only to learn better the logic behind things. I noticed from the logs of the test classes I'm writing that JUnit actually creates a class for each test method call. In other words, if I have a class MyTest that has the methods testA(), testB(), and testC() then Junit will create an instance of MyTest for each of the method calls.

Now one could argue that it is so that each test is treated as starting from fresh; however aren't the setUp() and tearDown() method exactly for that?

Regards,
Sim085
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:http://martinfowler.com/bliki/JunitNewInstance.html


Thanks, that was exactly what I was looking for :)
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem :)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!