There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
Originally posted by Stevi Deter:
Dave,
I think if you debug through the actual code in deleteRecipe, you'll discover
why the call to deleteRecipe is returning false and your test is failing.
Originally posted by dave hopkins:
So r1 is first passed to add recipe then the same r1 reference is passed to deleteRecipe. Therefore at some point this will be true
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Also, you have no way of being sure the add test runs before the delete test.
This assumption is not correct. JUnit creates separate objects for each test case - at least in the version I tried.
There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
Originally posted by dave hopkins:
Look at the code. I create r1 in the Test Object's contructor. What I believe you are referring to is the setUp() and tearDown() methods which is not what is being done here.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Lasse Koskela:
I can verify what Jeanne's saying:
1) JUnit creates a new instance of the test class for each test method.
Originally posted by dave hopkins:
Thanks for that guys. But if the constructor is run before every test
why is there a setUp() method?
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Jeanne Boyarsky:
Also, the JUnit founders have not guaranteed that a new object will be created for each test forever. It happens to be that way at this time and I suspect it will stay that way for a long time. But they have the flexibility to change things.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Jeanne Boyarsky:
The constructor for each test is run at the beginning. The setup is run after all the constructors are run. If the tests use a lot of memory or set up state in the database (for integration tests), it is good to have them run immediately before test execution. When there are thousands of tests memory issues could occur. (They haven't for us, but they could.) And for the database, the setUp can't be done all at once because the tests might need different data.
Originally posted by ankur rathi:
If constructor runs for each test method (test case) then it's same as setUp() method. What's the difference?
Originally posted by ankur rathi:
In fact I actually think that this depends on the runner you are using. As far as I know, a runner is allowed to reuse test instances when rerunning tests.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
vinita chauhan wrote:hey do anyone have Junit test cases source code for this coffeemaker application??
please send me as soon as possible
regards
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |