The TDD paradigm is another way to build software, but also another way to look at programs. The difference is that it's based on testing your components or even the application as whole while building it. Take a look into this amazing paradigm and its small variations and implementation for PHP frameworks.
- [Instructor] The TDD Paradigm, or Test-Driven Development is a way of developing software based on tests or test suites. It relies on testing tools to develop features that are tested from their conception. Requirements are written as test cases. Even if tests aren't passed, this is part of the paradigm. Tests are written before any code of the application. It might seem strange, but we could have a whole testing suite written prior to having any application code.
In TDD, we strive to test if not all, most of our code. There are tools such as PHP units, code coverage, which gives us an estimate as to the percentage of tested code. The whole idea is that once we have the test or test suite, we write code to have these tests. But now, let's take a look into the TDD Workflow. We will take a feature and abstract it into our software. Once we know what a feature is supposed to solve, then we write a test for that feature.
We will run the test knowing it will not pass, since we haven't written a test to pass it. Once we confirm our testing mechanism is working correctly, we will write code to pass the test. Once the test has passed, we run the rest of the tests. Sometimes we may pass an individual test, but we may have broken something somewhere else. Once all tests have passed, we start improving our test to be more efficient. We refactor it. We will be using two types of testing.
Unit testing refers to isolating a component and testing a component's functionality. With this type of testing, we may test a model away from the MBC context and determine if it works correctly. Functional testing refers to testing a feature with the whole context of the application. While there are more types of tests, we will only be seeing these two. In PHP, we have several tools we can use to implement TDD. As of now, PHPUnit is practically the most popular TDD tool there is in the market.
It helps us with the creation of unit tests. PHPSpec is a testing tool to make behavior driven development tests. Tests are written more like a story than a test. Codeception is a tool set to write unit functional and acceptance tests. You may test a single class or framework component or a page. Selenium is a browser automation tool. It has a WebDriver API of its own to create browser automated tests.
It is possible to test an entire web application as if it were a user on a web browser. Behat is an open source behavior driven development framework of PHP. It's heavily based on Symfony's components. And lastly, let's take a quick look at TDD Deployment Workflow. A staging environment will be an environment just like production, but without real customer data on the database. CircleCI can help us have this environment.
We will also need the same test suite we used locally on this environment. A possible scenario is the following: We develop a new feature, we test locally, all of our tests pass so we now launch into staging. Staging will run the test again. And only if these tests pass on this environment, our code will be merged into our base code.
- Building features with test-driven development
- Authenticating users
- Uploading files
- Deploying Laravel code