# Types of Testing ### Unit tests Unit Testing involves writing tests that confirm an individual function or piece of code works the way we want it to. You run unit tests constantly during the development process to ensure that everything is working, every time you make a change. We write a unit test for code that has a clear specific purpose, for example, we'll often write unit test for the individual functions in a program. The unit tests can then call the function without needing to run our entire application to make sure we know that the function behaves as we expect. ### Integration tests You use integration tests when you add new code to pre-existing code, to make sure that not only do all of the pieces work individually as expected, but also that they run together correctly without breaking. ### End-to-end testing Run your application from start to finish for all the user stories you can think of. This ensures that the program is ready to go live, and that the special details of deployment do not mess up the code you carefully tested on your local machine with unit tests and integration tests. You conduct end-to-end tests occasionally, maybe only a few times during a product’s life-cycle, as they are very time consuming and expensive. # Approaches ## BDD Behavior Driven Development (BDD) is an approach to building software. In BDD, instead of writing code and then seeing if it works, you write tests first and code second. This means you can use tests as an outline for the application code you actually want to write. - Behavior Driven Development is like creating a plan before you write your program - Start by describing how the program should work, then write code until it works the way you expect it to work - If your tests are good, you can be confident that your functions really do what they’re supposed to do #### Red > Green > Refactor 1. Write the tests, even though at first they’ll fail 2. Fix the function in the first way that comes to mind, just to get your tests passing 3. Go back and refactor the function for improvements, repeating the cycle until you’re ready to move on #### More info [Writing Great Unit Tests: Best and Worst Practices](https://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/ "Writing Great Unit Tests: Best and Worst Practices") ___ **Tags**: #testing