Skip to content

Instantly share code, notes, and snippets.

@waleedsamy
Last active November 29, 2015 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waleedsamy/5368caa102faf4300618 to your computer and use it in GitHub Desktop.
Save waleedsamy/5368caa102faf4300618 to your computer and use it in GitHub Desktop.
testing, content collected from web

“I don’t have time to write tests because I am too busy debugging.”

Why

  • T E S T S A R E G O O D D O C U M E N TAT I O N
  • TESTS REDUCE BUGS
  • TESTING FORCES YOU TO THINK
  • TESTS REDUCE FEAR

The goal of unit testing is:

  1. to isolate each part of the program, and
  2. show that the individual parts are correct

Types of Software Testing

The Concept of Unit Testing

  • A unit test is code written by a developer that tests as small a piece of functionality (the unit) as possible.
  • One function may have multiple unit tests according to the usage and outputs of the function.
  • Tests ensure
  • The code meets expectations and specifications: Does what it says it should do.
  • The code continues to meet expectations over time: Avoiding regression.

Structure of A Unit Test

  • Setup
  • Prepare an input
  • Call a method
  • Check an output
  • Tear down

Unit Testing Tools

  • Testing Frameworks
  • BDD vs TDD
  • Mocking Frameworks
  • Assertion Libraies
  • Test Runner
  • Automation

Unit Test Should Not:

  1. Access the network
  2. Hit a database
  3. Use the file system
  4. Call other non-trivial components

Unit Testing with Mocks

  • Every App has Layers such Front end, business layer, Data Access Layer, Data Layer
  • Unit Testing tests one layer
  • A Mock allows a dependency to be imitated so the Unit test can be isolated.

Executing Tests:

  • Manulally
  • i want to run only this test, so open terminal run your test runner and provide him with your test suite to run for you
  • Automatically
  • Build server compiles and runs tests as part of nightly build operation. (travis-ci get updated with new push to repo run test against these new changes of code, and notify with errors or passing of pushed code)

Unit Test Best Practices

  • Consistent
  • Atomic - not depend on any thing - MOCK
  • Single Responsibility - Test behavior, not methods -
  • No conditional logic or loops
  • No exception handling
  • Self-descriptive - Informative Assertion messages - By reading the assertion message, one should know why the test failed and what to do -

FIX the build

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