Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,270 --> 00:00:05,910
In this video we are going to see how we can write tests for our model classes and we are going to use
2
00:00:05,910 --> 00:00:12,930
the job class as an example so I can open the job file over here and I'm going to move it to the right
3
00:00:12,930 --> 00:00:14,070
window.
4
00:00:14,340 --> 00:00:21,570
And in particular we are interested in writing tests for that from map and to map methods that we used
5
00:00:21,570 --> 00:00:22,730
to read and write.
6
00:00:22,740 --> 00:00:28,590
They thought we'd faster and I think it's especially important to have test coverage for data that we
7
00:00:28,590 --> 00:00:34,880
read from faster because Firestone is a schema less database where the data is not structured.
8
00:00:35,010 --> 00:00:41,520
So adding tests to model classes is a good way to ensure that our client application processes the data
9
00:00:41,520 --> 00:00:42,210
correctly.
10
00:00:42,630 --> 00:00:48,810
So our next step is to create a new Dart file called job on this court fast.
11
00:00:49,410 --> 00:00:52,740
And here we are going to add some tests for this class.
12
00:00:52,740 --> 00:01:02,390
So let's start by importing the third test and then we can out the void Main method.
13
00:01:03,120 --> 00:01:09,280
And in here we can create a new group called from map.
14
00:01:09,570 --> 00:01:12,960
And this is because we want to test this method first.
15
00:01:13,200 --> 00:01:19,500
And the first test that we want to write should check that if we get a new data argument then we return
16
00:01:19,510 --> 00:01:20,290
no.
17
00:01:20,310 --> 00:01:29,850
So we're going to write a test called normal data and inside the test body we can write final job equals
18
00:01:30,000 --> 00:01:34,230
job dot from month with no.
19
00:01:34,740 --> 00:01:39,900
And then for example ABC has a document idea and we need to import job as well.
20
00:01:40,620 --> 00:01:47,040
And then we can have our next fact we job equals no like this.
21
00:01:47,220 --> 00:01:52,390
And I'm not going to run this but I can assure you that this test will pass.
22
00:01:52,530 --> 00:01:56,580
Next we need architects to check that when we pass a map.
23
00:01:56,580 --> 00:01:59,370
We've done name and our rate per hour.
24
00:01:59,460 --> 00:02:03,560
Then our job is created and the corresponding properties are set.
25
00:02:03,570 --> 00:02:14,730
So here we could create a new test named job with all properties like this and then we could create
26
00:02:14,730 --> 00:02:19,830
a final job equals job dot from map.
27
00:02:19,830 --> 00:02:31,010
And here we could pass a map with the name of for example blogging and a grade per hour of 10.
28
00:02:31,830 --> 00:02:38,780
And we could pass a document I.D. of ABC like this and then we need to write our expectations.
29
00:02:38,790 --> 00:02:48,480
So here we could type expect and then job dot name to be equal to blogging and then we could also expect
30
00:02:48,480 --> 00:02:53,550
that job growth rate per hour is equal to 10.
31
00:02:54,090 --> 00:03:00,420
And finally job dot deem to be equal to a b c.
32
00:03:00,420 --> 00:03:06,470
And at this stage we could run the tests and as we can see we got success.
33
00:03:06,890 --> 00:03:10,970
However I think that these three expectations are quite verbose.
34
00:03:10,970 --> 00:03:19,730
And instead I would prefer to write something like expect with job and then equal to job with name of
35
00:03:19,730 --> 00:03:29,450
blogging and rate per hour of then and job and I need to be a b c like this.
36
00:03:29,450 --> 00:03:35,820
So with this change I can remove the previous lines and then can run the test again.
37
00:03:36,290 --> 00:03:43,070
And as we can see this time we get an error saying that we expected an instance of job and the actual
38
00:03:43,070 --> 00:03:45,350
value was also an instance of job.
39
00:03:45,830 --> 00:03:48,550
So let's try to understand this in the next video.
4188
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.