Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
by
Lessons:25Length:2.9 hours

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

1.2 Test-Driven Development in Angular

In this video, I'll try to demystify the term Test-Driven Development and I'll look at a few alternative definitions.

Testing in Angular is not the same as testing a normal JavaScript application. There are many frameworks (an important selection of which we will learn in later videos) that are built specifically to test Angular apps. In this video, we'll take a birds-eye view of those libraries to get a sense of the landscape of testing for Angular.

1.2 Test-Driven Development in Angular

>> Hello ladies and gentlemen. In this video we're going to answer the question why test-driven development? You may have a lot of decisions to make when deciding the structure of your app. So, why should you decide to make it a test-driven development app? The first reason is that code which is backed up by tests is more reliable. The more tests you've written for a piece of code, the better you know its functionality, and the better you can define how it's going to work. We'll learn all about this as we write tests for our code. Another important detail is that when test is backed up by code, the responsibility of making sure it works doesn't lay on say the head developer or the intermediate developer, it's all sort of shared by the group, who as a whole maintains the quality of the test base. Another key advantage is it lets you focus, when writing the code, on writing the code itself. You don't need to write stuff into the code, like comments explaining what's its supposed to do, or its limitations. Because you can write tests that will describe this in your tests file. So, to many, what may be the most compelling reason to go with test-driven development is it lets projects meet needs that are very complex. You may work on a project and a list of needs may be 100 pages long with 1000 requirements. It's very difficult for one person to verify that all these requirements are met. However, automated testing shines for this and can really help you make sure your app is meeting many, many requirements. So, before you can answer the question, why is test-driven development right for you, you have to understand what test-driven development is. So, let's talk about that for a second. Basically when you write test-driven code, you're writing tests to make sure the code works. That's all there is to it. Now, once you've written these tests, you want your computer to run the tests automatically. This is called test automation and it's a big part of test-driven development. Finally, when you're writing test drive development you can't just write all your tests at the end together. You don't have to write them exactly before or at the same time. You can even write them two or three minutes after, but you have to write the tests basically at the same time. They should come in in the same call request. And finally, once you have written all those amazing tests, as a test-driven developer you'll use tools like, say, Istanbul to measure how much of your code you actually covered. Did you test very much of it? Or is half of your repository completely untested? So, how does this all fit in with Angular? As we'll see throughout this course, Angular was designed with a heavy emphasis on testing from day one. There are numerous hooks and features in Angular that allow us to test our code more efficiently and quickly. So, by choosing Angular you've made a good choice, we're at the very beginning, for a test-driven app. Additionally, we have a special tool called Karma which exists for running unit tests of many kinds, but almost especially for running unit tests with Angular. And we'll learn all about this. And finally we'll learn about Protractor, which is a tool for running very special tests, which tests your entire app from beginning to end. Protractor really lets you run tests that test stuff that is not simple, and by writing good end-to-end tests with Protractor you can really take your development to the next level. So, this is why you should do test-driven development, and I hope you'll enjoy the rest of the course.