WEBVTT

00:00:04.382 --> 00:00:06.620
Hi, my name is Joe Morris.

00:00:06.620 --> 00:00:10.420
I'm a program manager on
the .NET and Visual Studio team.

00:00:10.420 --> 00:00:13.730
In this video I'm gonna
show you a new feature

00:00:13.730 --> 00:00:17.780
that is released in the Enterprise
Edition of Visual Studio 2017

00:00:17.780 --> 00:00:20.090
called Live Unit Testing.

00:00:20.090 --> 00:00:23.080
Once you use this
feature you will realize

00:00:23.080 --> 00:00:25.390
that the current way of
running unit tests looks so

00:00:25.390 --> 00:00:30.350
old school when compared to
running it the Live Unit Test way.

00:00:30.350 --> 00:00:33.570
It will tremendously improve
your coding productivity and

00:00:33.570 --> 00:00:36.870
quality of code by showing
Unit Test results and

00:00:36.870 --> 00:00:40.710
code coverage live in
the editor while you're coding.

00:00:40.710 --> 00:00:44.690
This feature works with C Sharp and
BB projects for .net and

00:00:44.690 --> 00:00:49.520
supports test frameworks of ms test,
xUnit and NUnit.

00:00:49.520 --> 00:00:50.410
Let's see it in action.

00:00:51.430 --> 00:00:54.068
I have this bike shopping
app that I'm downloading.

00:00:54.068 --> 00:00:58.240
It runs esp.net on .net framework.

00:00:58.240 --> 00:01:01.230
It's a smart bike sharing system.

00:01:01.230 --> 00:01:04.000
Let me run the app to show
you what it looks like.

00:01:06.920 --> 00:01:12.050
App allows a user to get a bike,
purchase tickets to events, and

00:01:12.050 --> 00:01:14.300
ride the bike to the event.

00:01:14.300 --> 00:01:17.980
It also allows the user to do
targeted workout sessions for

00:01:17.980 --> 00:01:18.530
fitness.

00:01:19.640 --> 00:01:24.600
Okay, I will stop running the app
and show you the code I'm working on

00:01:24.600 --> 00:01:26.510
in class library for
my bike sharing app.

00:01:28.190 --> 00:01:33.532
Let me navigate to
project mybikes.domain

00:01:33.532 --> 00:01:37.750
logic and open file trainer.cs.

00:01:37.750 --> 00:01:40.760
I have a workout class and

00:01:40.760 --> 00:01:45.400
a trainer class that calculates
special metrics for my workouts.

00:01:48.249 --> 00:01:53.445
There is this method called
Get Workout With Best Speed to

00:01:53.445 --> 00:01:58.980
figure out on which of my workouts
did I go the fastest speed.

00:02:02.280 --> 00:02:04.400
I've written some unit test for

00:02:04.400 --> 00:02:08.130
this get workout with best
speed method all ready.

00:02:08.130 --> 00:02:12.660
Let me open that unit test side
by side with my library code.

00:02:17.324 --> 00:02:21.829
Let me navigate to the get workout
speed for two workouts unit test.

00:02:24.441 --> 00:02:28.470
In this unit test,
I registered workouts.

00:02:30.197 --> 00:02:33.157
One for
10 miles with 20 minutes speed, and

00:02:33.157 --> 00:02:35.905
the other 5 miles with
20 minutes speed.

00:02:38.195 --> 00:02:41.560
For this scenario,
when I complete the two accounts,

00:02:41.560 --> 00:02:43.742
my expected the result for

00:02:43.742 --> 00:02:48.935
workout with the best speed is the
10 miles workout within 20 minutes.

00:02:51.765 --> 00:02:55.550
The old school way of how I
used to run these unit test,

00:02:55.550 --> 00:02:58.200
was when manually going and
running the test,

00:03:01.109 --> 00:03:04.870
Then I see the results in
the test Explorer window.

00:03:07.035 --> 00:03:09.690
I will then look at the failed test.

00:03:11.362 --> 00:03:13.480
I spend some time looking at it.

00:03:14.930 --> 00:03:19.542
It tells me unit test failed
in line 43 of the unit test.

00:03:19.542 --> 00:03:22.860
Besides placing for,

00:03:22.860 --> 00:03:27.490
there is not much use for
info to pinpoint the failure.

00:03:30.100 --> 00:03:34.380
To see more code coverage
data on the fail test,

00:03:34.380 --> 00:03:38.850
I will typically run analyze
code coverage for failed test.

00:03:44.080 --> 00:03:48.790
It tells me what blocks are covered,
not covered.

00:03:50.040 --> 00:03:53.790
It still doesn't show any
visualization in the code editor.

00:03:55.160 --> 00:03:59.420
I can click on the show code
coverage coloring to show the blocks

00:03:59.420 --> 00:04:04.550
in the editor,
even then it is not easy to figure

00:04:04.550 --> 00:04:09.550
out which one is covered and
not covered, failing etc.

00:04:09.550 --> 00:04:15.370
Well, this is all the old
school way of doing unit test.

00:04:15.370 --> 00:04:18.970
Let's see the new way of doing
it by a live unit testing.

00:04:20.400 --> 00:04:23.310
Let's close code coverage results.

00:04:23.310 --> 00:04:29.370
Let's close test explorer and
go enable live unit testing.

00:04:29.370 --> 00:04:33.800
You enable live unit test
by going to menu, tests,

00:04:33.800 --> 00:04:36.112
live unit testing, start.

00:04:38.318 --> 00:04:42.979
Within a few seconds you will
see various clips showing in

00:04:42.979 --> 00:04:44.540
your code editor.

00:04:47.000 --> 00:04:54.370
Green checks indicate test
covered by unit test and passing.

00:04:54.370 --> 00:04:59.330
Red crosses indicate covered
by unit test code and failing.

00:05:00.710 --> 00:05:04.640
Blue dashes indicate
no unit test coverage.

00:05:07.399 --> 00:05:11.883
When I click on a red cross
I can see which tests

00:05:11.883 --> 00:05:15.790
specifically are passing or failing.

00:05:17.020 --> 00:05:20.640
I can select a test to
navigate to my test method.

00:05:22.660 --> 00:05:26.390
I can see that get work out
with the best speed is failing

00:05:26.390 --> 00:05:27.820
one of my test cases.

00:05:29.430 --> 00:05:34.170
As I'm looking at this I see that
the five-mile workout is being

00:05:34.170 --> 00:05:38.090
returned when the ten miles work
out clearly has the faster time.

00:05:40.010 --> 00:05:43.130
I can also see that the best
speed is never changing.

00:05:45.250 --> 00:05:47.080
I identify the bug in my code.

00:05:48.510 --> 00:05:52.310
I need to add another line
of code to fix my code.

00:05:52.310 --> 00:05:55.810
As soon as I make the code, watch
how the state of the calligraph

00:05:55.810 --> 00:05:59.890
changes from red x to green check

00:05:59.890 --> 00:06:03.600
indicating that workout with best
speed is passing the unit test now.

00:06:06.200 --> 00:06:11.100
Now let me scroll to another method
called guess most miles traveled.

00:06:12.250 --> 00:06:14.200
It shows a blue glyph.

00:06:14.200 --> 00:06:17.760
And when I hover over it,
it says covered by zero test.

00:06:19.260 --> 00:06:22.990
Okay, that means I need
to write a unit test.

00:06:22.990 --> 00:06:27.440
Let me switch to my unit test
project and add a unit test.

00:06:27.440 --> 00:06:32.810
For the sake of time I have already
returned one and commented it out.

00:06:32.810 --> 00:06:35.180
Let me uncomment and
add the unit test for

00:06:35.180 --> 00:06:37.160
get work out with
most miles traveled.

00:06:38.530 --> 00:06:42.820
As soon as they add the unit test,
system automatically runs it.

00:06:42.820 --> 00:06:45.500
And you can see how
GetMostMilesTraveled

00:06:45.500 --> 00:06:48.140
is covered in passing
the unit test now, and

00:06:48.140 --> 00:06:50.450
the coverage glyph turns
from blue to green check.

00:06:51.660 --> 00:06:52.970
That's very cool.

00:06:52.970 --> 00:06:57.050
I can see that all unit test
results that I passed now, and

00:06:57.050 --> 00:07:00.340
all my lines of code are covered
with the green check.

00:07:00.340 --> 00:07:03.620
I feel great about how live
unit testing helped me identify

00:07:03.620 --> 00:07:07.170
my product code bug, and
how quickly I could fix it and

00:07:07.170 --> 00:07:11.980
see my unit test result pass, and
code coverage turning to 100%.

00:07:11.980 --> 00:07:16.760
I allow it, and I'm certainly
going to keep live unit testing on

00:07:16.760 --> 00:07:18.180
all the time moving forward.

00:07:20.160 --> 00:07:23.640
As you can see, Live Unit Testing
is a great feature that will

00:07:23.640 --> 00:07:27.290
tremendously improve dollar per
productivity by showing unit test

00:07:27.290 --> 00:07:30.785
results and code coverage live
in the edit while you're coding.

00:07:30.785 --> 00:07:34.790
.NET developers out there,
please do check out this feature

00:07:34.790 --> 00:07:39.120
that is present in the Enterprise
Edition of Visual Studio 2017.

00:07:39.120 --> 00:07:40.693
Thanks for watching this video.

