You need to install the following extension and framework:
- Chutzpah VS Extension
- Jasmine Test Framework
You can do this from Nu-Get Package,
- Go ahead and install Angular Js Core Nu-Get Package.
- Delete Sample Controller and Jasmine sample files.
- Create appcontroller.js in Controller Folder. And insert following code:
- angular.module('app', []).controller('appController', function ($scope) {
- $scope.value = 5;
- Create a Test folder and create appcontrollertest.js file. Inside that test file put the below code:
- describe('When using appController ', function()
- {
-
- beforeEach(module('app'));
-
- var scope;
- beforeEach(inject(function($controller, $rootScope)
- {
- scope = $rootScope.$new();
- var ctrl = $controller('appController',
- {
- $scope: scope
- });
- }));
- it('initial value is 5', function()
- {
- expect(scope.value).toBe(5);
- });
- });
As you are using Jasmine framework, Describe is used to group the test cases together.
It: Chutzpah will detect ‘it’ as a unit test. So use ‘it’ to create individual test case.
- Right Click on the test file and run the Unit test case.
You will get the result as pass or fail. Also you can run the test cases either on test explorer or browser also.