2
3
4
5
TDD can also drive the design of a program (the programmer is concerned with the interface before the implementation);
6
The lower coupling between objects (CBO).
7
The total code implementation time could be shorter (and TDD cuts the costs);
8
9
10
11
12
13
14
15
16
17
18
19
20
What? Individual units of source code.
Why? Are tested to determine whether they are fit for use.
21
22
it('get series', function () {
$httpBackend.expectGET('http://server/series');
createShowInfoController();
$scope.getSeries();
$httpBackend.flush();
console.log('$scope.series shouldn't be empty');
except($scope.series.length).beGreaterThan(0);
});
23
> showInfoController get series FAILED
> Expect 0 to be greater than 0.
> at Object...
24
25
beforeEach(function() {
this.addMatchers({
toNotEmptyArray: function() {
this.message = function() {
return "Expected " + this.actual + " to be not empty";
};
return this.actual.length > 0;
}
});
});
26
expect(fn).toThrow(Error);
27
describe('#getSeries', function () {
it('should have function called getSeries', function () {...});
});
describe('when $scope.series.length is 0', function () {
it('should set $scope.isEmptyResult to true', function () {...});
it('should call showDefaultMessage', function () {...});
});
28
describe('seriesController', function () {
it('should init controller', function () {...});
it('should get series', function () {...});
describe('empty result', function () {
it('should configure module with defaults', function () {...});
});
});
29
30
31
32
33
34