1 00:00:00,000 --> 00:00:02,890 [No Audio] 2 00:00:02,890 --> 00:00:05,264 One last point to bear in mind, if I just set a 3 00:00:05,264 --> 00:00:10,664 breakpoint here and then debug test again 4 00:00:10,664 --> 00:00:15,531 when it's running the first test method, you can see 5 00:00:15,531 --> 00:00:19,097 here we have this calculator @816, which is the 6 00:00:19,097 --> 00:00:20,497 reference to the instance 7 00:00:20,497 --> 00:00:22,484 [No Audio] 8 00:00:22,484 --> 00:00:24,400 we just put a breakpoint here and here. 9 00:00:24,400 --> 00:00:26,413 [No Audio] 10 00:00:26,413 --> 00:00:28,664 So if I just play now, then we'll see the 11 00:00:28,664 --> 00:00:31,342 test add positive numbers is going to be executing 12 00:00:31,342 --> 00:00:34,344 against instance 816, we can see here. 13 00:00:34,344 --> 00:00:37,045 So I'll just play that. That's fine. 14 00:00:37,045 --> 00:00:41,084 And on the second test being executed, we can 15 00:00:41,084 --> 00:00:45,142 see now that calc is now a different instance. 16 00:00:45,142 --> 00:00:48,824 It's a different object Calculator@828, which 17 00:00:48,824 --> 00:00:50,120 means that when I end up in the second 18 00:00:50,120 --> 00:00:54,076 method testAddZeroToPositive, this test method 19 00:00:54,076 --> 00:00:56,576 is running against a different instance. 20 00:00:56,576 --> 00:00:58,459 Let's play that off. 21 00:00:58,459 --> 00:01:00,334 So it completes. 22 00:01:00,334 --> 00:01:02,564 So this is a good thing to point out is, 23 00:01:02,564 --> 00:01:05,575 the fact that the test fixture which you have and 24 00:01:05,575 --> 00:01:08,362 which you set up in the method which is annotated 25 00:01:08,362 --> 00:01:11,388 with @Before that's, set up fresh each time. 26 00:01:11,388 --> 00:01:13,882 Not only is the setup method called fresh 27 00:01:13,882 --> 00:01:16,064 each time, which creates a new instance of 28 00:01:16,064 --> 00:01:18,758 whatever objects your test fixture is composed of. 29 00:01:18,758 --> 00:01:21,572 Not only that, but also the test itself. 30 00:01:21,572 --> 00:01:25,148 The test class itself, is also recreated each time. 31 00:01:25,148 --> 00:01:28,181 And in addition to @Before, there's also @After, which 32 00:01:28,181 --> 00:01:32,170 is almost never used in JUnit, at least in unit tests. 33 00:01:32,170 --> 00:01:34,244 But that would enable you to tear down any 34 00:01:34,244 --> 00:01:36,158 state from the fixture which you wanted to do. 35 00:01:36,158 --> 00:01:37,844 But as I said, for unit tests in 36 00:01:37,844 --> 00:01:39,586 general, these are in memory, so we don't 37 00:01:39,586 --> 00:01:41,870 tend to use teardown methods for those. 38 00:01:41,870 --> 00:01:44,410 And finally, if you needed to do any setup 39 00:01:44,410 --> 00:01:46,768 which applies to all of the test methods. 40 00:01:46,768 --> 00:01:48,152 So you're really talking about doing 41 00:01:48,152 --> 00:01:50,498 test setup at a class level. 42 00:01:50,498 --> 00:01:51,860 Then there's also the @Before 43 00:01:51,860 --> 00:01:53,480 class annotation you can use. 44 00:01:53,480 --> 00:01:55,292 And again, there's a corresponding @After 45 00:01:55,292 --> 00:01:57,068 class annotation as well, which is the 46 00:01:57,068 --> 00:01:59,275 opposite from a tear down perspective. 47 00:01:59,275 --> 00:02:01,592 Anyway, that should give you some nice insight on 48 00:02:01,592 --> 00:02:03,466 how to use JUnit as a test framework. 49 00:02:03,466 --> 00:02:05,672 And now we're in a great position, where we can start 50 00:02:05,672 --> 00:02:08,252 to actually be prepared to use it to write our unit 51 00:02:08,252 --> 00:02:11,422 tests, which in turn use the Mokita Mocking library. 52 00:02:11,422 --> 00:02:12,919 And we'll see how to do this 53 00:02:12,919 --> 00:02:14,870 as we progress through the course.