Three stories about 

 testing 


Marina Miranovich

@obnoxious_mari

http://bit.ly/func2015


qr code

2

Table of contents




  • Novel 'About TDD';
  • Story 'About Unit testing';
  • Anecdote 'Just about testing'.

3







The novel 'About tdd'

4

Intro



5

TDD Pros





TDD can also drive the design of a program (the programmer is concerned with the interface before the implementation);

6

TDD Pros






The lower coupling between objects (CBO).

7

TDD Pros






The total code implementation time could be shorter (and TDD cuts the costs);

8

TDD Cost Profit



9

Cost of defect


10

chapter 1. legacy code


11

legacy code 'features'




  • Spaghetti-code;
  • Different technologies and approaches;
  • JS not ready for testing.

12

legacy code advice



Don't write every new piece of code without tests

13

chapter 2. have no time for testing


14

hot projects




  • Hackathon;
  • Proof of concept;
  • Your example...

15

have no time for tests. advice



Keep calm and write tests

16

chapter 3. want but can't


17

want but can't. advice



writing tests is a habit

18

Happy end



  • Sometimes you need some arguments;
  • It's never too late;
  • Make tests your habit;
  • Don't give up.

19







The Story 'About Unit testing''

20

intro. Unit testing



 What?  Individual units of source code.

 Why?  Are tested to determine whether they are fit for use.

21

anti-patterns




  • Not isolated test context;
  • Complex mocking;
  • Testing to much at once.

22

it becomes better


  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

test fails



  > showInfoController get series FAILED
  >    Expect 0 to be greater than 0.
  >      at Object...
            

24

'not good enough test' markers




  • console.log()
  • try {...} catch {...}

25

console.log > custom matcher


  beforeEach(function() {
      this.addMatchers({
          toNotEmptyArray: function() {
              this.message = function() {
                  return "Expected " + this.actual + " to be not empty";
              };
              return this.actual.length > 0;
          }
      });
  });
            

26

try/catch > expect error



  expect(fn).toThrow(Error);
            

27

hmmm...


  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

just unit test

 
  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

Happy end

anti-patterns

  • Not isolated test context;
  • Complex mocking;
  • Testing to much at once.


'not good enough test' markers

  • console.log()
  • try {...} catch {...}

30







The anecdote 'just About testing'

31

testing mind map


32

by testing layer


 

33

by targets

 

34

Thank you!


Marina Miranovich
twitter: @obnoxious_mari


Three stories about testing

By Marina Miranovich

Three stories about testing

  • 2,464