1 00:00:00,000 --> 00:00:02,650 [No Audio] 2 00:00:02,650 --> 00:00:04,003 In this video, we're going to write some very 3 00:00:04,003 --> 00:00:06,166 basic production code that we can write a unit 4 00:00:06,166 --> 00:00:08,558 test for and start coding the unit test itself 5 00:00:08,558 --> 00:00:11,541 by introducing you to the @Test annotation. 6 00:00:11,541 --> 00:00:13,291 Let's jump in. 7 00:00:13,291 --> 00:00:15,728 So let's go back into CalculatorTest. 8 00:00:15,728 --> 00:00:17,864 So currently now if I right click this, if 9 00:00:17,864 --> 00:00:20,218 I go up here and right click, then you'll 10 00:00:20,218 --> 00:00:21,402 see I can't do anything with it. 11 00:00:21,416 --> 00:00:23,643 There's no run, 12 00:00:23,643 --> 00:00:26,216 menu which I can use which will 13 00:00:26,216 --> 00:00:27,932 enable me to run it as a unit test. 14 00:00:27,932 --> 00:00:30,552 So to fix that, what I need to do 15 00:00:30,552 --> 00:00:34,594 is to put in a test method, public void 16 00:00:34,594 --> 00:00:38,776 this doesn't return anything testAdd. 17 00:00:38,776 --> 00:00:41,192 It's not going to take anything either, 18 00:00:41,192 --> 00:00:42,475 so that's going to be empty. 19 00:00:42,475 --> 00:00:45,390 [No Audio] 20 00:00:45,390 --> 00:00:47,672 Now, there are different ways of being able to name 21 00:00:47,672 --> 00:00:49,910 your test methods and we'll cover that in a later unit. 22 00:00:49,910 --> 00:00:51,108 But for now we're just going with 23 00:00:51,108 --> 00:00:52,994 an arbitrary convention of taking the method 24 00:00:52,994 --> 00:00:54,948 we're testing the method name there, which is add 25 00:00:54,948 --> 00:00:57,950 because we have in here a Calculator add method. 26 00:00:57,950 --> 00:00:58,958 You can see, 27 00:00:58,958 --> 00:01:00,891 [No Audio] 28 00:01:00,891 --> 00:01:03,096 I'm just prefixing it with the word test. 29 00:01:03,096 --> 00:01:05,712 So to make it a test, JUnit gives us these 30 00:01:05,712 --> 00:01:08,498 annotations which we can use as part of its API. 31 00:01:08,498 --> 00:01:09,996 And one of the annotations, probably the 32 00:01:09,996 --> 00:01:12,429 most important annotation is the 33 00:01:12,429 --> 00:01:14,768 org.junit test annotation. 34 00:01:14,768 --> 00:01:17,868 So if I just do @Test here from 35 00:01:17,868 --> 00:01:21,986 org.junit and hit enter, you can see we've 36 00:01:21,986 --> 00:01:23,842 imported it there, which means that now if I 37 00:01:23,856 --> 00:01:24,839 right click, 38 00:01:24,839 --> 00:01:26,839 [No Audio] 39 00:01:26,839 --> 00:01:28,648 you can see we have this new 40 00:01:28,648 --> 00:01:30,847 option here which is Run 'CalculatorTest' 41 00:01:30,847 --> 00:01:32,788 has now recognized that test case, due to the 42 00:01:32,788 --> 00:01:34,720 fact that we put the @Test annotation on it. 43 00:01:34,720 --> 00:01:35,860 So now we have a test to run 44 00:01:35,860 --> 00:01:37,564 and some production code we can actually test. 45 00:01:37,564 --> 00:01:39,371 Let's see how we can do that in the next video.