1
00:00:00,004 --> 00:00:02,002
- (Instructor) In continuous integration,

2
00:00:02,002 --> 00:00:06,000
delivery and deployment, testing plays a critical role

3
00:00:06,000 --> 00:00:08,006
in ensuring that each step ensures

4
00:00:08,006 --> 00:00:11,002
quality and bug free release.

5
00:00:11,002 --> 00:00:13,004
Many kinds of testing must be performed

6
00:00:13,004 --> 00:00:15,009
for applications such as integration testing,

7
00:00:15,009 --> 00:00:20,009
UI testing, load testing, security testing and so on.

8
00:00:20,009 --> 00:00:25,000
Most of these testing activities require automated tools

9
00:00:25,000 --> 00:00:28,009
which need to be integrated into the DevOps cycle.

10
00:00:28,009 --> 00:00:31,004
To keep it simple in this case study,

11
00:00:31,004 --> 00:00:34,001
we will look only at initial unit testing,

12
00:00:34,001 --> 00:00:36,004
which is part of the build process.

13
00:00:36,004 --> 00:00:39,005
It can be easily integrated into our current setup

14
00:00:39,005 --> 00:00:41,009
using the JUnit framework.

15
00:00:41,009 --> 00:00:46,002
But JUnit can help us test only non-servlet code.

16
00:00:46,002 --> 00:00:48,004
Our current code base is quite small

17
00:00:48,004 --> 00:00:51,008
with very little code outside servlets and JSPs.

18
00:00:51,008 --> 00:00:54,008
So just to demonstrate how to bring unit testing

19
00:00:54,008 --> 00:00:56,007
into our release cycle,

20
00:00:56,007 --> 00:01:00,001
I will put some simple test cases that tests

21
00:01:00,001 --> 00:01:04,000
the two new search methods we wrote in dow class.

22
00:01:04,000 --> 00:01:07,002
These test cases will become part of the cycle

23
00:01:07,002 --> 00:01:09,000
and the new bill will go through

24
00:01:09,000 --> 00:01:12,000
only if the test cases pass.

25
00:01:12,000 --> 00:01:15,009
For that I have written my test cases in test dow Java,

26
00:01:15,009 --> 00:01:21,000
which is inside the SRC test folder.

27
00:01:21,000 --> 00:01:24,000
And it is the same folder which is also mentioned in

28
00:01:24,000 --> 00:01:27,006
POM XMLS test source directory.

29
00:01:27,006 --> 00:01:29,009
That way Maven knows where to find test

30
00:01:29,009 --> 00:01:34,001
files to run before making a new build.

31
00:01:34,001 --> 00:01:37,000
So here is test dow dot java.

32
00:01:37,000 --> 00:01:40,008
Since we are doing unit testing, we do not want to connect

33
00:01:40,008 --> 00:01:44,001
to the database because that slows down testing.

34
00:01:44,001 --> 00:01:47,004
And also, we only want to test what we do

35
00:01:47,004 --> 00:01:50,005
after the data has been read from the database.

36
00:01:50,005 --> 00:01:55,003
So here, I have a setup class method in line 20

37
00:01:55,003 --> 00:01:59,002
that is executed before any tests are run.

38
00:01:59,002 --> 00:02:02,000
This method has fake data that initializes

39
00:02:02,000 --> 00:02:04,004
Dow's product and nutrient maps.

40
00:02:04,004 --> 00:02:06,008
With this fake data we want to test

41
00:02:06,008 --> 00:02:08,008
whether the two search methods in dow

42
00:02:08,008 --> 00:02:11,002
return correct results.

43
00:02:11,002 --> 00:02:13,001
My first test case

44
00:02:13,001 --> 00:02:17,007
in line 55 tests dow search product on names

45
00:02:17,007 --> 00:02:20,004
by passing these search string Apple to it,

46
00:02:20,004 --> 00:02:23,000
and then asserting that the returned list

47
00:02:23,000 --> 00:02:27,005
has size two based on the fake data I created about.

48
00:02:27,005 --> 00:02:30,006
My second test in line 61

49
00:02:30,006 --> 00:02:32,001
test the same Dow's method,

50
00:02:32,001 --> 00:02:34,000
but this time to check whether

51
00:02:34,000 --> 00:02:38,000
the return list has correct products in it.

52
00:02:38,000 --> 00:02:41,009
The third test in line 74,

53
00:02:41,009 --> 00:02:44,005
test the other search method in Dow.

54
00:02:44,005 --> 00:02:46,009
That is search nutrients in product

55
00:02:46,009 --> 00:02:49,004
by passing it an FDCID

56
00:02:49,004 --> 00:02:53,000
and asserting that it has three nutrients.

57
00:02:53,000 --> 00:02:55,003
The fourth test in line 80

58
00:02:55,003 --> 00:02:56,007
tests whether the nutrients

59
00:02:56,007 --> 00:03:00,003
in this product are the correct ones.

60
00:03:00,003 --> 00:03:03,002
Now we can add more tests to it, but for now,

61
00:03:03,002 --> 00:03:05,001
this suffices to demonstrate

62
00:03:05,001 --> 00:03:07,009
the build process that includes testing.

63
00:03:07,009 --> 00:03:11,005
And to do that, I go into project,

64
00:03:11,005 --> 00:03:14,002
right click run as

65
00:03:14,002 --> 00:03:19,006
and in Maven build gives the goal as test.

66
00:03:19,006 --> 00:03:22,001
Here you see that our tests

67
00:03:22,001 --> 00:03:25,006
have been run and our build is successful.

68
00:03:25,006 --> 00:03:30,000
I could also run Maven as with a gold package,

69
00:03:30,000 --> 00:03:31,008
which is what Jenkins will do.

70
00:03:31,008 --> 00:03:35,002
And this will run the tests and then create a war file.

71
00:03:35,002 --> 00:03:39,001
Now we are ready to commit our code for next release.

72
00:03:39,001 --> 00:03:41,004
Now that my code is on get,

73
00:03:41,004 --> 00:03:47,004
I can deploy it through Jenkins for that I say build now.

74
00:03:47,004 --> 00:03:50,003
So the build is now successful.

75
00:03:50,003 --> 00:03:52,006
I go to my EC two instance,

76
00:03:52,006 --> 00:03:55,006
pick up the DNS URL.

77
00:03:55,006 --> 00:04:01,001
Go to my browser 8080 red30

78
00:04:01,001 --> 00:04:05,006
when you can see the new homepage in search,

79
00:04:05,006 --> 00:04:08,001
let's search for apple pie.

80
00:04:08,001 --> 00:04:12,007
And you can see the products and the nutrients.

81
00:04:12,007 --> 00:04:14,008
If I change the product selection,

82
00:04:14,008 --> 00:04:17,000
the nutrient also change.

