Unit Testing From The Trenches



              Alexandru Bolboaca
       V1.0, because I embrace change
I write tests because I don't want this to happen
...and I don't want to be this guy
Agenda

   Some clarifications

    5 practical ideas

Answers to your questions
Clarification #1: What is a unit test?
A piece of code that checks a unit from
      the system under test (SUT)

        A unit = a class (basic)
    A unit = a behavior (advanced)
A unit test


              Arrange Given
               Act     When
              Assert   Then
Clarification #2: Types of tests
Clarification #3: When we write tests
Design, Code, Test = Test After

 Design, Test, Code = Test First
          Programming

Test, Code, Design = Test Driven
         Development
Clarification #4: Who writes the tests

    Technology-facing tests: Devs

Business facing tests: Analysts and Devs

    Critique tests: Testers and Devs
Clarification #5: Good unit tests
          Simple
           Fast
         Readable
       Independent
        Repeatable
        Easy to run
Clarification #6: Write tests for any tech




          … including bash scripting
Anything else to clarify?
5 Practical Ideas
Situation #1




     Cost: 12 hrs of business
Cause: “a time calculation that was
   incorrect for the leap year”
Practical Idea #1




The immune system of your product
Situation #2


Large proportion of tests that are:

              Slow
          Unpredictable
Practical Idea #2
Situation #3




    I measure the development time
I want the unit test coverage to be 90%
Practical Idea #3
Managers measure Running Tested
           Features

  Developers measure coverage

Guideline: Coverage must increase
Situation #4
       We have unit tests, BUT:

  We extensively use the debugger

  Unit tests are based on test plans

Testers still execute repeatedly manual
                 test plans
Practical Idea #4
Use automated developer tests to:


    Executable Specifications

       Replace debugging

      Complement learning

Replace repetitive manual testing
Situation #5
Practical Idea #5
Wrap up




I measure RTF/sprint
Alexandru Bolboaca
         alex.bolboaca@mozaicworks.com

         @alexboly, alexbolboaca.ro

          ●   Trainings: Unit Testing,
              TDD, Legacy Code
          ●   Technical Mentoring,
              Coaching, on-site
              and remote
Questions




The important thing is not to stop questioning

Alexandru Bolboaca - Unit Testing from the Trenches