1 00:00:00,000 --> 00:00:02,470 [No Audio] 2 00:00:02,470 --> 00:00:04,160 So in this video we're going to see an example 3 00:00:04,160 --> 00:00:06,764 of where we might want to ignore a test, which 4 00:00:06,764 --> 00:00:08,804 instructs the unit not to run that test. 5 00:00:08,804 --> 00:00:10,628 And we'll see where we might want to do this. 6 00:00:10,628 --> 00:00:12,300 Let's continue from before. 7 00:00:12,300 --> 00:00:14,564 Ok, so let's just make sure that we can still 8 00:00:14,564 --> 00:00:17,420 run all our tests, and run the test break 9 00:00:17,420 --> 00:00:19,040 which is a good habit to get into. 10 00:00:19,040 --> 00:00:20,458 So I'm going to src, test, java. 11 00:00:20,458 --> 00:00:22,391 And if you right click that folder, not the 12 00:00:22,391 --> 00:00:24,958 folder above you'll see this, Run 'All tests'. 13 00:00:24,958 --> 00:00:26,607 Now it's always a good idea to get into the habit 14 00:00:26,607 --> 00:00:28,892 of running all the tests whenever you make changes, 15 00:00:28,892 --> 00:00:30,740 just to make sure that you haven't broken anything. 16 00:00:30,740 --> 00:00:32,860 And also probably just do it mindlessly. 17 00:00:32,860 --> 00:00:35,074 Don't try and think about whether you've tested 18 00:00:35,074 --> 00:00:37,438 this particular production class and that might affect 19 00:00:37,438 --> 00:00:39,464 test classes A, B and C. 20 00:00:39,464 --> 00:00:40,892 Don't think like that, just run them. 21 00:00:40,892 --> 00:00:43,006 Because these tests should be very quick to execute. 22 00:00:43,006 --> 00:00:44,672 It should be a matter of seconds to get 23 00:00:44,672 --> 00:00:46,602 feedback to know that everything is still working as 24 00:00:46,616 --> 00:00:48,199 it was before we made a change and there's no 25 00:00:48,199 --> 00:00:50,565 regression which has been introduced, regression 26 00:00:50,565 --> 00:00:53,074 being the term to mean that we've moved backwards. 27 00:00:53,074 --> 00:00:54,878 In other words, we've broken something. 28 00:00:54,878 --> 00:00:56,636 That's when you get regression in tests, and 29 00:00:56,636 --> 00:00:58,268 that's something we're looking to avoid, which is 30 00:00:58,268 --> 00:00:59,974 why we always run these tests repeatedly. 31 00:00:59,974 --> 00:01:01,280 So run all the tests there. 32 00:01:01,280 --> 00:01:06,330 [No Audio] 33 00:01:06,330 --> 00:01:07,464 And now you can see that in doing 34 00:01:07,464 --> 00:01:09,876 this I've actually broken something, because at this 35 00:01:09,876 --> 00:01:11,484 point I get a stack trace when this 36 00:01:11,484 --> 00:01:14,114 particular test which is testAuthenticate executed. 37 00:01:14,114 --> 00:01:16,644 Now this means either that the production code has 38 00:01:16,644 --> 00:01:18,756 changed in some way, which has broken some kind 39 00:01:18,756 --> 00:01:22,284 of invariance or truth to be true about the 40 00:01:22,284 --> 00:01:25,071 system, in the assertions of that test once the test 41 00:01:25,071 --> 00:01:27,864 has been executed, or alternatively just broken the 42 00:01:27,864 --> 00:01:30,398 test itself by when the method has been invoked, 43 00:01:30,398 --> 00:01:32,618 that methods are an exception, or alternatively, 44 00:01:32,618 --> 00:01:34,104 it can also be an indicator that 45 00:01:34,104 --> 00:01:36,396 our assertions now need to change. 46 00:01:36,396 --> 00:01:38,700 They need to become somehow different or maybe 47 00:01:38,700 --> 00:01:41,484 broader with the new production change we've made. 48 00:01:41,484 --> 00:01:43,890 Now obviously here I'm just creating, you know 49 00:01:43,890 --> 00:01:46,586 pretty much a static list. Not literally statically. 50 00:01:46,586 --> 00:01:48,182 I just mean the list isn't changing. 51 00:01:48,182 --> 00:01:50,498 It's not dynamic, it's not stored in the database. 52 00:01:50,498 --> 00:01:52,812 But I'm just creating a static list here of some 53 00:01:52,812 --> 00:01:56,358 users to represent what the persistence layer would do. 54 00:01:56,358 --> 00:01:57,866 But this implementation in fact could be 55 00:01:57,866 --> 00:02:00,854 representative of, for example, when in the persistence 56 00:02:00,854 --> 00:02:02,930 layer we've changed a SQL statement. 57 00:02:02,930 --> 00:02:04,932 So imagine you've changed a SQL statement and 58 00:02:04,932 --> 00:02:07,164 now you're opening the floodgates to also let 59 00:02:07,164 --> 00:02:09,264 these different types of user through. 60 00:02:09,264 --> 00:02:11,666 So maybe you've extended, for example, a table, you've 61 00:02:11,666 --> 00:02:14,316 added these extra attributes which are for whether the 62 00:02:14,316 --> 00:02:16,046 user is live and what the type of user 63 00:02:16,046 --> 00:02:18,264 is, and when you've changed that query, the call 64 00:02:18,264 --> 00:02:20,712 to this UserRepository method is now letting those 65 00:02:20,712 --> 00:02:22,513 different types of objects through. 66 00:02:22,513 --> 00:02:25,596 So let's look at why the test failed and then we 67 00:02:25,596 --> 00:02:27,962 can fix it, almost specifically then we can evaluate 68 00:02:27,962 --> 00:02:30,696 what was wrong and then work out how to fix it. 69 00:02:30,696 --> 00:02:34,192 So I can see here this is the test 70 00:02:34,192 --> 00:02:37,188 method that was called AuthenticationServiceTest. 71 00:02:37,188 --> 00:02:39,674 So if I click this and then click the method 72 00:02:39,674 --> 00:02:43,404 it called I'm going to define my username call. 73 00:02:43,404 --> 00:02:45,319 At this point I might be thinking, 74 00:02:45,319 --> 00:02:47,583 well, what's happened there? Because you know 75 00:02:47,583 --> 00:02:49,766 it's AuthenticationServiceTest that looks okay, it's 76 00:02:49,766 --> 00:02:52,966 authenticating further no assertions but it's calling 77 00:02:52,966 --> 00:02:54,808 it and then something like that looks okay, there's 78 00:02:54,808 --> 00:02:56,544 nothing wrong there. But yeah, if I go back to your 79 00:02:56,544 --> 00:02:59,669 test, you can see here that what we're expecting or 80 00:02:59,669 --> 00:03:01,986 rather what we've arranged is that the userRepository 81 00:03:01,986 --> 00:03:03,902 is going to throw an IllegalArgumentException 82 00:03:03,902 --> 00:03:06,086 and ask yourself from a demonstration from a previous 83 00:03:06,086 --> 00:03:08,318 unit, where we spoke about how writing unit tests 84 00:03:08,318 --> 00:03:10,356 will enable us to rethink about designs and everything. 85 00:03:10,356 --> 00:03:11,724 We're not going to address that here. 86 00:03:11,724 --> 00:03:13,896 So for now I'll just show you how you can avoid 87 00:03:13,896 --> 00:03:15,984 dealing with those issues immediately and only 88 00:03:15,984 --> 00:03:17,616 ever do that for good reason by the way. 89 00:03:17,616 --> 00:03:20,816 But we can do that now just by putting on @Ignore. 90 00:03:20,816 --> 00:03:24,130 [No Audio] 91 00:03:24,130 --> 00:03:26,324 So now if we go back here to Run 92 00:03:26,324 --> 00:03:28,204 and then Run All in myapp which means 93 00:03:28,204 --> 00:03:30,753 are all the test again, everything should be okay. 94 00:03:30,753 --> 00:03:32,553 [No Audio] 95 00:03:32,553 --> 00:03:35,212 And it is, but we do also get a notice here that one 96 00:03:35,212 --> 00:03:38,140 test was ignored and there were two tests in the 97 00:03:38,140 --> 00:03:40,504 test suite and it's okay to do this in this 98 00:03:40,504 --> 00:03:43,384 example because I'm not addressing this here. 99 00:03:43,384 --> 00:03:46,036 We'll address this another time and I want to 100 00:03:46,036 --> 00:03:47,704 move on to show you something else and so 101 00:03:47,704 --> 00:03:48,940 this is a useful thing to do. 102 00:03:48,940 --> 00:03:51,294 It's useful to be able to have this @Ignore 103 00:03:51,294 --> 00:03:53,944 to enable you to postpone fixing up the tests while 104 00:03:53,944 --> 00:03:56,477 you make changes which for example might temporarily 105 00:03:56,477 --> 00:03:59,502 break things. But again use it judiciously and don't 106 00:03:59,502 --> 00:04:02,162 let it be a go to thing which you always use just to 107 00:04:02,176 --> 00:04:04,767 never fix anything up, because inevitably the longer 108 00:04:04,767 --> 00:04:06,676 you leave things, then the more difficult it's going to 109 00:04:06,676 --> 00:04:09,026 become to fix that test up as the implementation 110 00:04:09,026 --> 00:04:11,056 changes. Well, that's effectively been on 111 00:04:11,056 --> 00:04:13,050 pause for this @Ignore annotation. 112 00:04:13,050 --> 00:04:15,498 So there it is the @Ignore annotation. 113 00:04:15,498 --> 00:04:17,964 Just remember to always use it judiciously.