[PHP] [LaravelTest] unitization test: Getting started

Source: Internet
Author: User
[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

  1. The file to be tested is stored in the tests Directory. the name of the Test file is Test. Php, such as ProductTest. php.
  2. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.