[PHP] [LaravelTest] unitization test: this article applies to beginners who have a certain understanding of PHP and laravel frameworks and have read the laravel getting started video: Laravel 5 Fundamentals. This document describes how to use a unitized testing tool to test applications.
The related video laravel test has been downloaded to the online storage. if you haven't seen it yet, please download it first:
- Link: http://pan.baidu.com/s/1sjXeLQH
- Password extraction: jjb5
- The file to be tested is stored in the tests Directory. the name of the Test file is Test. Php, such as ProductTest. php.
- The test method name must start with test to start the test. Test class name input command: vendor/bin/phpunit tests/unit/ProductTest. php
Test file ProductTest. php
AssertEquals ('Fallout 4', $ product-> name (); // The Object name is Fallout 4 }}
Class file Product. php
name = $name; } public function name() { return $this->name; }}
Pass test
The setUp () method can simplify the code.
Product = new Product ('Fallout 4', 59);} function testAProductHasName () {$ this-> assertEquals ('Fallout 4 ', $ this-> product-> name (); // The Object name is Fallout 4} function testAProductHasCost () {$ this-> assertEquals (59, $ this-> product-> cost (); // The Object name is Fallout 4 }}
Summary
This article is only a preliminary introduction and will be further elaborated.