[php] view plain copy <?php class StackTest extends PHPUnit_Framework_TestCase { public function testEmpty() { $stack = array(); $this->assertEmpty($stack); return $stack; } /** * @depends testEmpty */ public function testPush(array $stack) { array_push($stack, 'foo'); $this->assertEquals('foo', $stack[count($stack)-1]); $this->assertNotEmpty($stack); return $stack; } /** * @depends testPush */ public function testPop(array $stack) { $this->assertEquals('foo', array_pop($stack)); $this->assertEmpty($stack); } } ?>
1. What is unit testing?
[Baidu Encyclopedia] Unit testing is to check and verify the smallest testable unit in the software.
is a small piece of code written by the developer to check whether a small, clear function of the code under test is correct.
2. What is its function?
【Nonsense】Check the feasibility and stability of software and programs.
Unit testing can avoid repeated and redundant problems during iteration, upgrade, etc. processes.
Avoid affecting your logic when others modify the code
3. Which programs require unit testing (PHP)?
[Ideal] The ideal unit test should cover all possible paths in the program, including correct and incorrect paths. A unit test usually covers a specific path in a function or method.
[Reality] Functions in model, helper, and controller must be tested and the paths cover all possibilities
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
19 Apr 2024
Using GoogleTest for unit testing in a C++ function library ensures its reliability. The specific steps are as follows: Install GoogleTest to create a unit test for the function library: Create a ".test.cpp" file and include the GoogleTest header definition inherited from::testing::Test The test case class creates a test method starting with TEST. Run the unit test: use the gtest executable file and pass in the test case file. Use other assertion macros: ASSERT_EQ (abort the test), ASSERT_TRUE/ASSERT_FALSE (check the condition), ASSERT_THROW (check the exception throw out)
20 Dec 2017
First of all, we need to understand the concept of unit testing. Unit testing refers to testing the basic units in the software, such as functions, methods, etc., to check whether their return values or behaviors are as expected, but it is actually very responsible, because it is It consists of many components, and the execution process is connected together. To test unit fragments, you need to provide execution context (or parameters) and environment (such as piling to simulate some objects) for running.
25 Oct 2017
This article mainly introduces how to use the PHP unit testing framework PHPUnit. I hope this article can help everyone understand and master this part of the content.
09 Mar 2024
PHPUnit is a framework for streamlining unit testing in PHP. When combined with jenkins, you can incorporate testing into your CI (continuous integration) process and run tests on every code change. PHPUnit Plugin for JenkinsThe PHPUnit plugin for Jenkins allows you to easily add PHPUnit tests to your Jenkins jobs. This plugin runs tests, displays results, and automatically notifies you of failed tests. Installing and configuring PHPUnitPHPUnit
01 Aug 2024
Today I was running my tests and had a failing test: Tests\Common\BusinessLogic\XXX\XXLogicTest::testInvalidXX with data set #9 ([['dsadsa', 'dsafsdfsd', 1234.23, -1234.23, '', 'dsadsa']]) Failed asserting that 1 matches expected 0. /var/www/html/
05 Jul 2018
This article mainly introduces PHPstorm to configure PHPunit to unit test the PHP code introduced by composer. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
Hot Tools
PHP library for dependency injection containers
PHP library for dependency injection containers
A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking
Small PHP library for optimizing images
Small PHP library for optimizing images