Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save narainsagar/fcd57c346d0676af1e5f5557ea7faacf to your computer and use it in GitHub Desktop.
Save narainsagar/fcd57c346d0676af1e5f5557ea7faacf to your computer and use it in GitHub Desktop.
Test Driven Development (TDD)

Learning Plan for Test Driven Development (TDD)

These learning resources primarily focus on Test Driven Development (TDD).

  • There is an emphasis on learning using PHP, Laravel and PHPUnit.
  • All these resources are free (at the time of writing)

Table of Contents

1. Videos

2. Blog Posts

3. Books, manuals and websites

4. Tooling

  • VS Code
    • Extension: Better PHPUnit (video)
      • Configure CTRL + T to run tests, CTRL SHIFT + T to rerun
  • PHPUnit (doc 8.0)
    • Recommended to install per project:
      • composer require --dev phpunit/phpunit ^|version|
      • e.g. composer require --dev phpunit/phpunit ^8
      • Included with dev dependencies on the laravel framework.
    • Install globally, configure phpunit.bat and add to path (not recommended but useful for running from the command line).

5. Three Laws of TDD

Over the years I have come to describe Test Driven Development in terms of three simple rules. They are:

  1. You are not allowed to write any production code unless it is to make a failing unit test pass.
  2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
  3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test.

Uncle Bob's full article: Source

6. Examples & Code Kata

7. Project With Tests

  • October CMS - Based on Laravel, on setup there is a full set of tests to run. (Runtime ~10 min - with xdebug on), turn xdebug off if not generating reports
    • October has been installed and run, examine the tests in more detail, what are they testing, etc.
  • Laravel Boilerplate - Tests take 10 min to run (with xdebug on), turn xdebug off if not generating reports
    • Laravel Boilerplate has been installed and run, examine the tests in more detail, what are they testing, etc.

8. Conclusion

Notes are still ongoing and may not necessarily make sense out of context.

  • TDD, when used correctly are good.
  • Documentation can be created from well named tests.
  • Test behaviour not implementations.
  • Testing is an art, there isn't a right way for everything.
  • Testing takes practice
  • Try to use real objects rather than mock data.
  • Tests should be trustworthy.
  • Anna Filina (Recap)
    • Write a test to prove what is being tested works.
    • Write tests when you see a bug
    • Write test when you improve code
    • Write tests as you write new code
    • Write tests before you write code
    • Text unexpected scenarios
    • Testing = Pre-emptive Debugging
  • Google
    • Small - like unit testing
    • Medium
    • Large - acceptance testing
  • Mocking can cause dependencies or coupling.
  • Ensure that both success and failure cases are covered by appropriate unit tests
  • There's a lot of value in reading books on good coding and design practices even if they don't focus on unit testing
  • TDD is recommended for any long lasting project which may need new features in the future.

9. Other Learning Plans

The next plan from TDD was Learning Plan for Design Patterns and Principles of Good Design

10. License

Copyright (c) 2019 Pen-Y-Fan

Permission is hereby granted, free of charge, to any person obtaining a copy of this learning plan and associated documentation files (the "Plan"), to deal in the Plan without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Plan, and to permit persons to whom the Plan is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Plan.

Content copied from Wikipedia.org is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment